UNIX C Programming

Chapter 1: Getting Ready



This chapter serves to introduce the student to the C language. It does not require the student to write C programs. The objectives important to this chapter are:

  • Explain C's history and features
  • Examine the steps needed to write programs
  • Discuss the process involved in compiling and linking a C program
  • Look at C standards used throughout the book

The C language was created in 1972 by Dennis Ritchie and Ken Thompson. They designed C to be a useful language.

The design of C makes it natural for users to use top-down planning, structured programming, and modular design. Important features of C include:

  • C is an efficient language
  • C is a portable language
  • C is powerful and flexible
  • C is oriented towards the programmer

In the 1990s, many software houses have moved to C++. C++ is nearly a superset of C.

C is a compiled language. The seven steps important to writing a C program are:

  1. Define the program objectives
  2. Design the program
  3. Write the code
  4. Compile (the code)
  5. Run the program
  6. Test and debug the program
  7. Maintain and modify the program

Most new students of C (and all other languages, for that matter) neglect steps 1 and 2. Advise students to develop the habit of planning before coding. This will save them considerable time over the longer term.

When a C program is written, it is stored as a source code file. The filename consists of a basename and an extension. For example, in budget.c, budget is the basename; c is the extension. In a DOS environment, the basename is not allowed to exceed 8 characters.

After source code is written it must be converted into an executable file. Conversion consists of two steps: compiling and linking. Compiling converts source code into intermediate code (the object code resulting from the source code). Linking brings together three elements: the start-up code, code for library routines, and the intermediate code.

Programming mechanics differ depending on the computing environment. In a UNIX C environment, editing must be done with a general-purpose editor (such as vi or emacs). A program is compiled by typing cc, followed by the source code filename, as in

	cc inform.c

The executable file produced is always named


This file must be renamed, if you want to keep it.

In a DOS environment, command line compilers require different compiler commands. For example, Microsoft C asks the user to type cl, followed by the source code filename. The executable file produced ends with a .EXE extension. Thus,

	CL inform.c

leads to


To run a DOS executable file, type


Integrated development environments (IDEs) are popular with current DOS software products. These products feature a built-in editor and menus designed to allow the naming and saving of a source code file and the compiling and saving of the executable file. Object files are also saved in a DOS environment.

Why compile? Compiling leads to faster-running programs than interpreted programs.

Currently many C standards are available; however, ANSI C is the standard. ANSI (American National Standards Institute) C provides a standard for the C language and for C libraries.

Remind students of the conventions used in the text. First, all programs are written using a different font. Second, computer output is printed in color. Third, the Enter key stands for Enter, c/r, and Return.

Finally, review the final statement in the Chapter summary. "Programming in C can be taxing, difficult, and frustrating, but it also can be intriguing, exciting, and satisfying." Students may need to be reminded of this statement as they work their way through the text.