How can I compile and run C in Xcode?

Our teacher is teaching use some Data Structures algorithms that are being implemented in C. He uses Visual Studio in class, but I want to be able to run simple programs that we write in Xcode.

I've tried to run the code but in Xcode 5 the options to do so are greyed out. Besides just installing Xcode, what steps should I need to take so that I can run simple C programs on my Mac?


  • Open Xcode
  • Select File->New->New Project
  • Select macOS (OS X in older versions) -> Command line tool
  • Choose C as type
  • Fill out the name and the other relevant wizards parts you need
  • click the main.c file to select it

And you should be good to go


In Xcode 6 & 7, you can do the following steps:

Creating the File

  1. Select File > New > Project > OS X
  2. Select Command Line Tool
  3. Click Next
  4. Input your Product Name and choose C as the language
  5. Click Next
  6. Choose where to save your project.
  7. Click Create

Running the Code

  1. Select Product > Run
  2. Check the console to check result.

That's it!

Check your the main.c file and you'll find a pre-filled 'Hello World' code in the editor. Good luck!


The above answers are all great. I'll just add my $0.02. I like using Xcode where it is basically just a text editor (not the more complex Xcode...which I need to get used to!).

So, here's what you can do:

  1. Click on Xcode
  2. Ignore the pop-up window asking about a new project
  3. At the top of your monitor, select "File"
  4. Select "New"
  5. Select "File"
  6. You can then select a C file as your option.

You can skip steps 3-5 with command + N!

You'll get a basic editor you can write your code in (nice syntax coloring, basic display, etc.).

Then, you can just compile and run your program in your terminal window (your standard gcc file and ./a.out stuff).