Very sadly having problems with the hello world program in C.

Discussion in 'Mac Programming' started by Dragonlance1561, Dec 6, 2008.

  1. Dragonlance1561 macrumors member

    Dragonlance1561

    Joined:
    Aug 16, 2007
    #1
    ok I know this sounds dumb but it really isn't working right!

    this is my code:
    #include <stdio.h>

    int main()
    {
    printf("Hello World/n");
    return 0;
    }

    I saved that as a .c file to my home directory

    next I opened terminal.app, and this what I did and the problem that followed: (Soroshi is the name of my home directory)

    Last login: Sat Dec 6 00:11:07 on ttys000
    macbook-pro:~ Soroshi$ gcc hello.c -o hello.app
    macbook-pro:~ Soroshi$ ./hello.app
    Hello World/nmacbook-pro:~ Soroshi$

    My issue is that the /n shouldn't have appered and the "macbook-pro:~ Soroshi$" should have appeared on the next line.

    btw I'm using the gcc compiler that came with Xcode which I downloaded from the apple ADC website.

    hope that all makes sense!
     
  2. SydneyDev macrumors 6502

    Joined:
    Sep 15, 2008
  3. Dragonlance1561 thread starter macrumors member

    Dragonlance1561

    Joined:
    Aug 16, 2007
    #3
    omg I can't believe i didn't see that! I feal really dumb now...
    oh well... everyone makes mistakes thats how we learn!

    another question though. how do I compile from a folder such as /home/documents/C programs instead of having to put it in my home directory to compile them because that could get annoying.
     
  4. Padraic macrumors regular

    Joined:
    Aug 30, 2007
    Location:
    Somewhere between here and there...
    #4
    you should just be able to drop to a terminal, change to your working directory and compile...

    If for some reason that doesn't work try this from your /home/documents/C programs directory

    Code:
    gcc ./hello.c -o hello.app
     
  5. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #5
    You don't need the .app extension when compiling a simple C program.
     
  6. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    Not only don't you need it, but it is very misleading. A .app is an application package that is basically a directory with a lot of support files as well as the executable that is run when you "launch" a package. Traditionally in UNIX executables have NO extension, and are set to executable, so it is easy to tell these files in a directory listing from other types.

    -Lee
     

Share This Page