Error Running Hello World

Discussion in 'Mac Programming' started by bftiedt, Mar 26, 2012.

  1. bftiedt, Mar 26, 2012
    Last edited by a moderator: Mar 26, 2012

    macrumors member

    Joined:
    Feb 12, 2008
    #1
    hey guys Im reading The C programming Language and trying to run hello world in xcode and keep running into a problem. The code im using is..
    Code:
    #include <stdio.h>
    library
    main ( )
    
    {
    
       printf ("hello, world/n" ) ;
    
    }
    
    When I click run to compile it in xcode i get an error saying, unknown type name "library". Any ides what im doing wrong here? Thanks
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    The problem is the word "library". I've hilited it in red.

    Do you think you need that word? Why? What did you read that tells you to put it there? Exactly which edition of "The C Programming Language? Which page? What authors (Kernighan & Ritchie)?

    In short, please describe how you came to have the word "library" there.
     
  3. thread starter macrumors member

    Joined:
    Feb 12, 2008
    #3
    After looking at the code again i realized the PDF I have pushed Library into the line of code when it was in fact supposed to be part of another sentence lol . Thanks for the help!
     
  4. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #4
    Be careful cutting+pasting from PDF's it doesn't work often.
     
  5. thread starter macrumors member

    Joined:
    Feb 12, 2008
    #5
    I was actually typing it out ( I think its easier to remember when actually typing) it just put library right into the line of code so it confused me quite a bit.
     
  6. macrumors 603

    Joined:
    Aug 9, 2009
    #6
    This is one reason for always identifying exactly what you're looking at, and exactly what you're working from, whether that's a book, an online tutorial, or a PDF.

    If someone with experience can actually look at the exact same file, web page, or book page as you're seeing, then we can probably give a relevant comment. If we don't know exactly what you're seeing, then all we can do is guess.

    I make this point now, even after you've solved the problem, because you still haven't identified exactly what you're looking at. I'm not aware of any PDFs of K&R's "The C Programming Language", but I could be wrong. Maybe yours is an old one, and a later version has it fixed. Maybe yours has some kind of formatting defect, unique to wherever you got it from. That's all just guessing, because we don't know exactly what you're looking at.
     
  7. macrumors newbie

    Joined:
    Jan 3, 2012
    #7
    I haven't looked at C in a little while, but I think your code should also read:

    Code:
    printf ("hello, world[COLOR="Red"]\[/COLOR]n" ) ;
    Since the new line character is "\n".
     

Share This Page