A noob needing help with C

Discussion in 'Mac Programming' started by ETID, Mar 17, 2008.

  1. macrumors regular

    Joined:
    Jan 6, 2008
    #1
    Hello I've started a programming in C course for my engineering degree. At the moment I'm using Visual C++/C to do this but I was just wondering if there is a similar variant for mac as I prefer to work in OSX than XP.

    Thanks for any help.
     
  2. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Every Macintosh comes with XCode, which comes with compilers for C, C++, Objective-C, Java, plus perl, python, ruby, and a few other languages.
     
  3. thread starter macrumors regular

    Joined:
    Jan 6, 2008
    #3
    Awesome. Is this located on the install disc?
     
  4. macrumors newbie

    Joined:
    Mar 10, 2008
    Location:
    New Hampshire
    #4
    Yes, it is on the install disc. Or you can download it from the Developers site at Apple. I just started C myself and xcode is great. If you find any good sites with tutorials or a good book, please let me know!
     
  5. thread starter macrumors regular

    Joined:
    Jan 6, 2008
    #5
    It looks gr8 but unfortunately I haven't been able to get even a simple hello world in C to work. I just get like 120 errors, have no idea what is going on.

    If anyone does know of a tutorial site or similar that would be awesome
     
  6. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #6
    Give us some details and we might be able to solve the problem.

    No details = no help in this forum I'm afraid.
     
  7. thread starter macrumors regular

    Joined:
    Jan 6, 2008
    #7
    right so I just want write a simple C code to begin with. I thought this was how I would go about doing it. Xcode>new project>blank project>new file>c file.

    I then input this code in
    /*hello world*/
    include <stdio.h>
    main()
    {
    printf ("hello world\n");
    }

    If that helps what I'm on about.

    I'm used to using visual c++/C for this so I didn't really know what to do for some things. For instance where I regularly use (hash symbol)include etc. What do I do as macs don't seem to have a hash key
     
  8. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #8
    You main function should be int main (int argc, const char * argv[]).

    Do not make a blank project.

    Xcode > New Project > Command Line Utility > Standard Tool.
     
  9. macrumors 65816

    Vader

    Joined:
    Oct 11, 2004
    Location:
    St. Louis, MO
    #9
    you are including a header file, does that header file exist?
     
  10. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #10
    Ah good eyes :).

    Yes look again at your include statement as well.
     
  11. thread starter macrumors regular

    Joined:
    Jan 6, 2008
    #11
    thanks got it working. Thanks to all you very nice people
     
  12. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #12
    I use Xcode every day for C/C++ programs and it's great. You can, however, also use the command line in Terminal. It's pretty simple.

    Code:
    cat > myprog.c
    #include <stdio.h>
    int main(void) { 
    printf("Hello World!\n") ; 
    return 0 ; 
    } 
    CTRL+D 
    
    gcc myprog.c -o myprog 
    ./myprog 
    
    is all it takes. ;)
     
  13. thread starter macrumors regular

    Joined:
    Jan 6, 2008
    #13
    When doing this in terminal how would you get the hash for the #include <stdio.h> because I don't have one on my keyboard and even if I use a windows keyboard the hash key just turns into a backslash.
     
  14. macrumors 6502

    Joined:
    Sep 17, 2003
    #14

    In UK Keyboard setup it's alt-3 to get a #.
     
  15. thread starter macrumors regular

    Joined:
    Jan 6, 2008
    #15
    Thanks for the alt-3 its a life saver! Since i started this thread I've already made so much progress.

    cheers
     

Share This Page