please help i'm so new to this you wouldn't believe

This is a discussion on please help i'm so new to this you wouldn't believe within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> main() { printf("hello world\n"); } why wont this work :( keeps telling me no newline at end ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    13

    Unhappy please help i'm so new to this you wouldn't believe

    Code:
    #include <stdio.h>
    
    main()
    {
    	printf("hello world\n");
    	
    }
    
    why wont this work :(  keeps telling me no newline at end of file but i thought this was "\n" am i wrong??

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    End of file is probably where the last brace is, and you haven't got a newline on that line - I'm only guessing, as this sort of thing is hard to show here.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Not having a new line at the end of the file shouldn't be a problem, the compiler just gives you a warning and adds the new line itself.
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by hauzer View Post
    Not having a new line at the end of the file shouldn't be a problem, the compiler just gives you a warning and adds the new line itself.
    Unless you use "-Werror" or similar - which may be a good thing to have on some projects - particularly at schools!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    13
    you mean

    return 0;

    ?? still doesn't work

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    13
    Thanks your right it just a warning but still works

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need a newline (if you press Ctrl-End on the keyboard, you should end up at the end of the file, and just make sure that's a "empty line" - the compiler will sometimes give this error for a line that contains a single space or tab.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,027
    Code:
    #include <stdio.h>
    
    int main()
    {
    	printf("hello world\n");
    }
    // Added to force board to show extra newline
    (Note the extra newline on the end.)
    Also remember to always use int main, not implicit main. http://cpwiki.sourceforge.net/Implicit_main
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21