Start Coding C on your Mac

Posted:
in Mac Software edited January 2014
Here is a short tut on how to start coding C on your Mac. I went through some trouble to find this info so, I thought it might help some people if I made a tutorial on what to do. (I did this on a Intel Core Duo OSX 10.4 Mac, so for other Macs it might be slightly different) This is my first tutorial so bear with me!



1. To tell if you have already done this, go to terminal and type "gcc" and hit enter. If it says something about no input files that means you have this already installed. If not, go to step 2.



2. Get your OSX install CDs, and take CD one and put it in your disc drive.



3. Wait a for a window to pop up that says, "Mac OS X Install Disc 1". Then click the Xcode Tools folder, you might need to scroll down to see it.



4. Click XcodeTools.mpkg and follow through on the installation (Its straightfoward).



5. Go to your Hard-Drive and check to see if their is a Developer folder. If you are intrested in using Xcode to develope applications go to step 6, otherwise skip it and go to step 7.



6. Click the Developer folder and then the Applications folder and you should see your Xcode and Interface Builder icons. I havn't used Xcode so, im not going to say anything else about it since I don't want to give false information.



7. Go to Terminal and type "gcc" and hit enter. If it tells you something about no input files, you did everything right. If not, try installing the Developer Tools again or ask for help from someone who knows a lot about Macs.



8. Make a file called helloworld.c on your desktop, with the following code:

#include <stdio.h>



main()

{

printf("Hello World\

");

return(0);

}




9. Go to Terminal and type the following command:

gcc /Users/YOURNAME/Desktop/helloworld.c -o helloworld

If you get an error, check to make sure you copied the code correctly.



10. Type ./helloworld into Terminal and it should output "Hello World!".



Congradulations, you just got C working on your Mac! Post any questions here and I will try to help. If you want to learn more about the gcc command, check here.



EDIT:

For some cocoa/c tutorials check out: http://forums.appleinsider.com/showp...72&postcount=6

Comments

  • Reply 1 of 7
    gongon Posts: 2,437member
    Most informative first (second?) post ever.



    Welcome to AppleInsider!
  • Reply 2 of 7
    Thanks for the welcome , and that was my first post :P
  • Reply 3 of 7
    Nice, it would have been great to have known this back when I took my C programming class last year.
  • Reply 4 of 7
    Even better than using the Developer Tools package on your DVD would be to go to connect.apple.com and sign up for the free developer program and download the latest XCode package.
  • Reply 5 of 7
    I feel like an expert! Don't forget about http://cocoadevcentral.com/
  • Reply 6 of 7
    Wow, that site is good, i will mention it in the post and give you credit for posting about it
Sign In or Register to comment.