472,122 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

fatal error C1004: unexpected end-of-file found

4
After compiling my C++ file I ended up with: fatal error C1004: unexpected end-of-file found

So I went true the code from the top to the bottom about six
times to see if I could find a forgotten { or ) and so on, but it looks alright
to me. In the main() function I placed a couple of breakpoints where input is expected but the compiler ingores if there aren't any.
Jan 18 '10 #1
15 21566
Banfa
9,065 Expert Mod 8TB
Breakpoints are only any use if you have got to the point of running the program in a debugger. If you have a compiler error you have no program so you would be able to run it in a debugger. You need to fix the compile error.

We could probably help but you didn't post the code we have about as much chance of telling you what your error is without the code as you have of guess what colour mug I am drinking tea from.
Jan 18 '10 #3
donbock
2,425 Expert 2GB
If you can't find anything wrong with the syntax of your source file then go to the last line of the source file and add a newline. A missing newline at the end of the file is pretty much invisible to you.
Jan 18 '10 #4
MKO32
4
Thank you for you reply. There is not much point going to Microsoft as they come up with answers whitch never got anything to do with the question you ask.
Jan 18 '10 #5
MKO32
4
Thank you for your quick reply. I've been trying to post the code but it is a very big file I can't get it back in an organized way in the small text box. I gave up maybe an idea for the moderator to change this small thing for something bigger. Anyway that is noy the isue. I deleted al the empty lines from the bottom and left one blank. I noticed that when I clicked on the error in the out-screen it jumped strait to the second line on the top, whitch is blank. Could it be that there is something wrong with one of the header files?

Thanks for your help so far,


Marcel
Jan 18 '10 #6
donbock
2,425 Expert 2GB
Actually, the MSDN link provided by alexis4 says that a missing newline at the end of the source file can trigger a c1004 error.

Did you make the error go away?
Jan 18 '10 #7
donbock
2,425 Expert 2GB
Regarding a possible header file problem ... the MSDN link informs us that another cause of the C1004 error is a #if without a matching #endif. Check the indicated header file for unbalanced conditional-compilation directives ... or unbalanced braces, parentheses, etc.
Jan 18 '10 #8
Banfa
9,065 Expert Mod 8TB
If you can post the whole code post the few lines round the error line.

post your code between [code ... [code] tags copy and past it from your editor it will appear like this
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     return 0;
  4. }
  5.  
If you need the edit box to be bigger use the up and down arrows on the right hand side of the edit box toolbar. If you go advanced you can use the # button to put code tags into your post by highlighting the code you want enclosed and pressing the button.

And finally the Microsoft website actually has a lot of useful information and the error descriptions are on the whole completely relevant and pedantically acurate. Do not blame that (or any other) website for your lack of experience in debugging code.
Jan 18 '10 #9
johny10151981
1,059 1GB
HI MK
You try to check whether curly bracket({}) or whatever it is combination is okay. From My exp in vc if they are not okay you may get error like this.

regards,
JOHNY
Jan 19 '10 #10
MKO32
4
Hello,

I think I found the culprit. There is one line of code whitch I was not realy certain off. So for just of the heck of it I commented it out and hit F5. In the end
I was released from the c1004 code but instead I've got an other 15 errors back. I know that that has got something to do with the fact that I'm trying to re-code from C+ to C++. So I will get stuck in there and try to solve it error by error. I thank everybody here for the time they spend on my problem, I realy do appreciate this and I'm glad I found this forum. See you all.

Marcel
Jan 19 '10 #11
weaknessforcats
9,208 Expert Mod 8TB
I usually get this error when a file does not have a null line at the end. Every file has to have an empty line as the last line.
Jan 19 '10 #12
Banfa
9,065 Expert Mod 8TB
<nitpick>
Actually I think you will find that what the standard says is that every line of code must end in an end of line sequence (new-line, new-line/carridge-return etc).
</nitpick>

I thought the MS compiler didn't check for this particular requirement.
Jan 19 '10 #13
johny10151981
1,059 1GB
gcc compiler create a warning if a new line is absent at the end of program code(found this on gcc compiler shift with suse 11.0)

johny
Jan 20 '10 #14
Banfa
9,065 Expert Mod 8TB
I used to work on a project that had different 3 platforms. The main body of the work (which was standard C) was developed on a 68000 platform and there were 2 or 3 people responsible for the builds and platform specific code on the other 2 platforms. Of the 3 platforms only the compiler for 1 actually checked for a new-line at the end of the last line of code (i.e. at least 1 blank line at the end of the file). It used to produce this message

error: Newline missing at end of file - inserting

However as you can see it was an actual error, not a warning, and would halt the compilation and therefore the build.

Of course the compiler that did this was not the one for the 68000 platform that the majority of the development team was using so the 1 poor chap that was using this platform was always on at the rest of the team about this particular requirement up until a rigerous procedure and using PcLint and code reviewing was instigated.
Jan 20 '10 #15
weaknessforcats
9,208 Expert Mod 8TB
<nitpick>
Actually I think you will find that what the standard says is that every line of code must end in an end of line sequence (new-line, new-line/carridge-return etc).
</nitpick>
I think I mis-said.

What I meant to say was that if you don't press enter on the last line of the source file, you get the no-end-of-file error. I think this is per the standard you are quoting.
Jan 20 '10 #16

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Tim Tyler | last post: by
1 post views Thread by Janwillem Borleffs | last post: by
6 posts views Thread by Ehartwig | last post: by
4 posts views Thread by Z.K. | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.