To directly answer your question: Yes, you most definitely can use Xcode to write and compile C code.
That out of the way, if you're going to learn C, at least while you're just getting started, I'd say it's a good idea to learn how to use gcc from the command line. It's actually simpler than something like Xcode for small programs, and you'll get a better idea of the steps involved in building a program. The essential procedure is:
Type your program into a text editor (TextEdit comes with Mac OS X, and will work). Save the program as a plain text file with the extension ".c". Here's a really simple program:
Code:
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
After you've done that, open Terminal (in /Applications/Utilities), and at the prompt type something like:
gcc /path/to/your/program/yourprogram.c -o program
Where "/path/to/you/program/' is the path to your .c file, "yourprogram.c" is the name of the file you saved with your text editor and "program" is the name you want your program to have after it's compiled.
GCC will compile your program, or give you information about errors in your source code if there are any. Assuming no errors, it will create an executable file, which you can run by typing:
./program
(replacing "program" with the name you put after "-o" in the gcc command above).
If it works, you'll see something like
$>./hello
Hello World!
$>
The easiest way to get GCC is indeed to install Xcode, which includes GCC. You can get Xcode on the Mac App Store.