fatal error C1004: unexpected end-of-file found

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MKO32
    New Member
    • Jan 2010
    • 4

    #1

    fatal error C1004: unexpected end-of-file found

    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.
  • alexis4
    New Member
    • Dec 2009
    • 113

    #2
    http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      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.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        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.

        Comment

        • MKO32
          New Member
          • Jan 2010
          • 4

          #5
          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.

          Comment

          • MKO32
            New Member
            • Jan 2010
            • 4

            #6
            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

            Comment

            • donbock
              Recognized Expert Top Contributor
              • Mar 2008
              • 2427

              #7
              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?

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                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.

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  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
                  Code:
                  int main()
                  {
                      return 0;
                  }
                  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.

                  Comment

                  • johny10151981
                    Top Contributor
                    • Jan 2010
                    • 1059

                    #10
                    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

                    Comment

                    • MKO32
                      New Member
                      • Jan 2010
                      • 4

                      #11
                      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

                      Comment

                      • weaknessforcats
                        Recognized Expert Expert
                        • Mar 2007
                        • 9214

                        #12
                        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.

                        Comment

                        • Banfa
                          Recognized Expert Expert
                          • Feb 2006
                          • 9067

                          #13
                          <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.

                          Comment

                          • johny10151981
                            Top Contributor
                            • Jan 2010
                            • 1059

                            #14
                            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

                            Comment

                            • Banfa
                              Recognized Expert Expert
                              • Feb 2006
                              • 9067

                              #15
                              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.

                              Comment

                              Working...