1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

A noob needing help with C

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

  1. macrumors regular

    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


    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. macrumors regular

    Awesome. Is this located on the install disc?
  4. macrumors newbie

    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. macrumors regular

    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


    Give us some details and we might be able to solve the problem.

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

    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>
    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


    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


    you are including a header file, does that header file exist?
  10. macrumors 603


    Ah good eyes :).

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

    thanks got it working. Thanks to all you very nice people
  12. macrumors 6502a

    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.

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

    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


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

    Thanks for the alt-3 its a life saver! Since i started this thread I've already made so much progress.


Share This Page