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


    Aug 16, 2007
    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, 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
    macbook-pro:~ Soroshi$ ./
    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

    Sep 15, 2008
  3. Dragonlance1561 thread starter macrumors member


    Aug 16, 2007
    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

    Aug 30, 2007
    Somewhere between here and there...
    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

    gcc ./hello.c -o
  5. Cromulent macrumors 603


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


    Jan 10, 2005
    Dallas, TX
    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.


Share This Page