You can write C programs using either the command line or Eclipse. I recommend using Eclipse.
Edit and save the file(s) with a text editor such as gedit, jEdit, emacs, or vi.
At the terminal window, navigate into the directory in which the
file(s) are saved. You can do this using the cd command, as in
cd directoryName
.
Compile the file(s) using the gcc command as in
gcc -Wall fileNames
.
If compilation was successful, then you can execute the
program by executing the a.out file created by
gcc: type ./a.out
.
Eclipse is a powerful program written for developing programs of all types. It was originally developed for writing Java programs, but it handles C (and C++) nicely if you include a very nice standard extension called CDT. Both Eclipse and CDT are already installed on the Linux laboratory computers, but if you want to install it on your own computer, I can suggest the following.
For a Linux computer, installation is relatively simple, assuming
you already have a C compiler installed (as most installations will
do by default): Under the Help menu, go to submenu and select Find
and Install.... Select Search for new features,
and enter
http://download.eclipse.org/tools/cdt/releases/callisto
as the download site. Click Finish. Select CDT when
prompted.
For Windows, I haven't tried it, but this PDF tutorial from the University of Manitoba seems to describe the process step by step. (I'll be happy to post a different link if somebody finds better instructions for Windows.)
In the following, I'll assume you already have CDT installed.
First, you need to create your project. Under the File
menu's New submenu, select Project. In the first panel, select
C Project
(under C/C++).
Enter a name in the next panel and click Finish.
(Important: choose a project name that does not include
any space characters — this has been known to cause
problems.)
Eclipse will prompt you about changing the perspective. You
want to do this.
Now create your program by creating a new Source File
(using the File menu's New submenu).
For the Source Folder
field, click Browse…
,
select your project name, and then click OK.
For the Source File
field, type the name of a file
ending in .c
, such as count.c. You can now edit
the program.
Once you have edited this file to contain the code you want to execute, you will need to build the project. In the Project menu, select Build All (or press control-B). If any errors result, Eclipse will flag them at this point. (In contrast to how it handles Java programs, Eclipse won't notice the errors until you build the project.)
To execute the program, go to the Run menu and select Run (or press control-F11). You only have to use the menubar once. After that, the green Play button in the toolbar will repeat whatever you last ran. For that matter, the hammer button in the toolbar will build the project a second time.