Locate the 'Terminal' application and double-click on it to open a terminal. I'll create a folder called "compsci":
[ltoma@lobster:~]$ pwd /home/ltoma [ltoma@lobster:~]$ mkdir compsci [ltoma@lobster:~]$ cd compsci/ [ltoma@lobster:~/compsci]$ ls [ltoma@lobster:~/compsci]$Inside it, I'll set up a folder for the first C program:
[ltoma@lobster:~/compsci]$ mkdir hello [ltoma@lobster:~/compsci]$cd hello
Once you open the editor you can start typing the first program:
#include < stdio.h > int main() { printf("Hello world!\n"); return 1; }Save this program as "~/compsci/hello/hello.c". (The symbol "~" expands in Unix to the name of your home directory).
[ltoma@lobster:~/compsci]$ cd hello/ [ltoma@lobster:~/compsci/hello]$ ls hello.c [ltoma@lobster:~/compsci/hello]$ ls -l total 4 -rw-r--r-- 1 ltoma cs 78 Sep 8 22:51 hello.c [ltoma@lobster:~/compsci/hello]$Note the file is readable and writeable to the owner, and readable only to everybody else. The file is not executable.
gcc hello.cI suggest you use the -g flag to include debugging information (stored in a dsym folder, see below):
gcc -g hello.c
[ltoma@lobster:~/compsci/hello]$ gcc -g hello.c [ltoma@lobster:~/compsci/hello]$ ls -l total 12 -rwxrwxr-x 1 ltoma cs 7641 Sep 9 12:23 a.out -rw-r--r-- 1 ltoma cs 78 Sep 8 22:51 hello.c [ltoma@lobster:~/compsci/hello]$Note that a.out is executable. You can run it:
[ltoma@lobster:~/compsci/hello]$ ./a.out hello, world [ltoma@lobster:~/compsci/hello]$
a.out is the default name for the executable. To specify a different name use option "-o":
[ltoma@lobster:~/compsci/hello]$ gcc -g hello.c -o hello [ltoma@lobster:~/compsci/hello]$ ./hello hello, world [ltoma@lobster:~/compsci/hello]$ ls a.out hello hello.c [ltoma@lobster:~/compsci/hello]$ rm a.out [ltoma@lobster:~/compsci/hello]$I suggest you also use option "-Wall" to generate all warnings:
[ltoma@lobster:~/compsci/hello]$ gcc -g -Wall hello.c -o hello [ltoma@lobster:~/compsci/hello]$