Complete Noob Question - learning C Hello World problems

Discussion in 'Mac Programming' started by ParishYoung, Mar 18, 2008.

  1. ParishYoung
    Expand Collapse
    macrumors 6502a

    Joined:
    Mar 18, 2008
    Location:
    Bristol, South West UK
    #1
    Hi All,

    I am completely new to programming and am currently learning C using X-Code and an ebook I downloaded from Spiderworks.com

    It's a real beginner course and I am stumbling at the first block.

    I have downloaded the Xcode program which opens and runs fine.

    However when using the simple example programs which are designed to simply display text on the screen.

    When I press build and go i get another window showing that "build was successful" but there is no output of the relevant text.

    Here is the code (remember it's only C):

    #include <stdio.h>

    void SayHello( void );

    int main (int argc, const char * argv[])
    {
    SayHello();
    SayHello();
    SayHello();

    return 0;
    }


    void SayHello( void )
    {
    printf( "Hello, world!\n" );
    }


    Please can someone tell me where I'm going wrong?

    Many thanks in advance.

    Parish
     
  2. antibact1
    Expand Collapse
    macrumors 6502

    Joined:
    Jun 1, 2006
    #2
    You have to EXECUTE the program. Compiling only builds a binary that you are able to execute.
     
  3. TEG
    Expand Collapse
    macrumors 604

    TEG

    Joined:
    Jan 21, 2002
    Location:
    Langley, Washington
    #3
    printf need a format qualifier after your string so you need

    printf("Hello World!\n", %s);

    then just gcc file.c

    then ./a.out

    TEG
     
  4. ParishYoung
    Expand Collapse
    thread starter macrumors 6502a

    Joined:
    Mar 18, 2008
    Location:
    Bristol, South West UK
    #4
    Doesn't the "Build and Go" button compile it and then run it??
     
  5. ParishYoung
    Expand Collapse
    thread starter macrumors 6502a

    Joined:
    Mar 18, 2008
    Location:
    Bristol, South West UK
    #5
    @TEG

    I literally started the ebook this morning so what you say is still double dutch to me.

    What is GCC??
     
  6. Cromulent
    Expand Collapse
    macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #6
    No it doesn't.

    printf("Hello World!\n"); is perfectly valid code. Your version is not, format qualifiers are used when you want to insert a variable in the string that printf prints. Not to specify what the string actually is.
     
  7. martintyler
    Expand Collapse
    macrumors newbie

    Joined:
    Feb 9, 2005
    #7

    ??? The original printf is fine. Yours wont even compile.
     
  8. Cromulent
    Expand Collapse
    macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #8
    Go to the run menu and click on Console. Then click build and go and you will see your output in the console window.
     
  9. ParishYoung
    Expand Collapse
    thread starter macrumors 6502a

    Joined:
    Mar 18, 2008
    Location:
    Bristol, South West UK
    #9
    @Cromulent

    Thanks man. When I did that it showed all of the 50 thousand times i'd presses Build and Go.

    Thanks to all for they help here. Lets see how I get on.
     

Share This Page