How to Use C on a Unix System

The C programming language is used extensively in Unix. Every Unix and Unix-based operating system comes with a C compiler installed by default. Since 1973, the Unix operating system has been written entirely in C. Using C allows you to interact with the Unix kernel with low level system calls as well as create high level programs. The same C program can also be compiled on many different systems, making it useful for cross platform applications.

Instructions

    • 1

      Create a text document that contains your program. For this example, use the well known "Hello World" program.

      #include <stdio.h>
      main()
      {
      printf ("Hello World!\n");
      }

    • 2

      Save the program with the .c extension. This program is named example.c

    • 3

      Open a terminal window. The terminal window will be found in the Utilities submenu on most Unix systems.

    • 4

      Change to the directory where you saved your program. cd MyProgs/

    • 5

      Issue the command "cc -o example example.c" to compile the program.
      The "-o" option tells the compiler to name the compiled program "example". Without it, the resulting program will be named "a.out".

    • 6

      Run the program by issuing the command: ./example

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured