![]() |
|
#1
|
|||
|
|||
Error: unexpected end of file found?ive written a c++ program with my own function defined to compute the numer n less than m so that both n+a and n+b are also prime. so what i did was write a function triples(int m, int a, int b) to get c++ to find out the primes n, n+a and n+b, then my main int main() was to implement this. (this is how i was told i had to do this).at the end i only get 2 errors, they are as follows:
error C2601: 'main' : local function definitions are illegal cpp(65) : fatal error C1004: unexpected end of file found Error executing cl.exe. 17563c2.exe - 2 error(s), 0 warning(s) the 1st is related to the first curly bracket underneath where i have written int main() and the final error is for the very last curly bracket right at the end of the program. why are these errors ocuuring and how can i get rid of them? this is my program (its quite long): CPP / C++ / C Code:
Last edited by LuciWiz : 26-Mar-2006 at 09:30.
Reason: Please insert your C code between [c] & [/c] tags
|
|||
|
#2
|
|||
|
|||
|
missing a closing brace in your triples function.
__________________
spasms!!! |
|
#3
|
|||
|
|||
|
Well, your first problem could very well be the fact that you have 5 open { brackets but only 3 close ones in your triples() function. Try something like this:
CPP / C++ / C Code:
EDIT: Oops, machinated beat me to it, oh well. |
|
#4
|
|||
|
|||
|
haha yeah i didn't bother to go thru his code, just counted his braces
__________________
spasms!!! |
|
#5
|
|||
|
|||
Re: error:unexpected end of file found?Ok, now I have to ask the question that likely no one wants to think about.
What about when such an error is not caused by the brackets? In other words, I have some code (that I actually cannot show all of due to the grounds of this work), and have counted all the brackets for all the files, but there is no missing }. Yet I still get the error. |
|
#6
|
||||
|
||||
Re: error:unexpected end of file found?You know, you wouldn't have to count braces if you used proper and consistent formatting in your code.
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#7
|
|||
|
|||
Re: error:unexpected end of file found?Quote:
Unexpected end-of-file can be caused by unmatched {} braces, unmatched [] brackets, unmatched () parentheses, unmatched " " double quotes, unmatched ' ' single quotes, missing semicolons, improperly formed if or for statements, and probably other things that don't just jump off of the top of my little pointed head at the moment. (Many of these might give other errors or warning messages, depending on context and depending on what compiler you are using, and the level of error reporting that is enabled. Does your compiler give any messages other than the one you posted?) So: How big is your file? If it is really huge, then I have to ask whether you wrote (and wrote and wrote) all of that code without trying some compiles along the way. I personally wouldn't (ordinarily) put more than a few tens of lines of code into a new file without doing a test compile. I write the functions one at a time and at least compile them before going on to the next. Often I have a skeleton test program in place so that I can actually test the functionality incrementally. (But that's just me; not everyone works the same way.) If you are really stuck, then here's a suggestion: Start with a new (empty) file. Put your #include stuff and whatever function prototypes you need at the top, and then just add one function. Try a compile. Add another function. Try a compile. Etc. Regards, Dave |
|
#8
|
|||
|
|||
Re: error:unexpected end of file found?I agree with davekwx. His method of coding s the prereffe method for all programmer.
Besides that, u also can try to comment out some function and compile. I hope this help. |
|
#9
|
|||
|
|||
Re: Error: unexpected end of file found?hai Peter,
I have an opinion, to better use Switch statements and avoid more if statements, that may improve your code execution speed... The problem you faced was with the missing braces... regards... Maxiiiiiii |
Recent GIDBlog
Problems with the Navy (Officers) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| Can't view pages from another machine on the Intranet | aevans | Apache Web Server Forum | 9 | 14-May-2004 02:26 |
| Re: Programming Techniques | WaltP | C Programming Language | 0 | 09-Mar-2004 23:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The