Programming in C for UNIX
Contents
1 Introduction
1.1 The classification and significance of C
1.2 Program structure and basic characteristics
1.3 Notes for the user of this manual
2 C programming for the beginner
2.1 Your first C program
2.2 Computations and function call
2.3 General remarks on definitions
2.4 Conditional execution and program loops
2.5 Summary
3 Syntax elements
3.1 The metalanguage
3.2 List of syntax elements
4 Types, storage classes, variables and constants
4.1 Types and definitions
4.1.1 Variable definition
4.1.2 Array definition
4.1.3 Enumeration types
4.1.4 Renaming types using typedef
4.1.5 Function definitions and declarations
4.2 Names, storage classes and initialization
4.2.1 Storage classes
4.2.2 Initialization
4.3 Constants
5 Operators and expressions
5.1 Type conversion in expressions
5.2 Unary operators
5.3 Arithmetic operators
5.4 Logical operators
5.5 Bitwise logical operations
5.6 Conditional expression operator
5.7 Assignment operators
5.8 Precedence of operators and execution sequence of operations
6 The C statements
6.1 The assignment
6.1.1 Value of an assignment
6.1.2 Type conversion in assignments
6.1.3 Compound assignment operators
6.1.4 Increment/decrement statements
6.2 Compound assignments and block structure
6.3 The if statement
6.4 The switch and break statements
6.5 The while statement
6.6 The for statement
6.7 The do while statement
6.8 The continue statement
6.9 The return statement
6.10 Labels and the goto statement
6.11 The dummy statement
7 Functions and the program structure
7.1 Notation and position within the program
7.2 Control flow
7.3 Transferring values to functions
7.4 Recursive functions
8 Pointers
8.1 Notation and the use of pointers
8.2 Pointers and arrays
8.3 Pointers as function arguments
8.4 Pointer arrays
8.5 Pointers to functions
8.6 Function arguments of the main function
9 Structures
9.1 The use of structures
9.1.1 Defining structure types and structures
9.1.2 Initializing structures
9.1.3 Referencing structure members
9.2 Pointers to structures
9.3 Arrays of structures
9.4 The sizeof operator
9.5 Self-referencing structure types
9.6 Fields
9.7 Unions
10 The C preprocessor
10.1 Substitution of names and macros
10.1.1 Defining symbolic constants
10.1.2 Parameterized name substitution
10.1.3 Undefining names
10.2 Including other source files
10.3 Conditional compilation of program segments
10.4 Line number control
11 Input/output
11.1 Standard input/output library and
11.2 Input/output from/to standard input/output
11.2.1 Character input/output using getchar and putchar
11.2.2 Formatted output using printf
11.2.3 Formatted input using scanf
11.2.4 Formatting in memory
11.3 File access
11.3.1 UNIX file philosophy
11.3.2 Opening files
11.3.3 Character input/output using getc, putc and ungetc
11.3.4 Line input/output using gets, puts, fgets and fputs
11.3.5 Field input/output using fread and fwrite
11.3.6 Formatted input/output from/to files
11.3.7 Random access: positioning and testing the data pointer
11.3.8 Input/output buffer control
11.3.9 Flushing the output buffer
11.3.10 Closing files
11.4 Buffering in temporary files
11.4.1 System temporary files
11.4.2 User-managed temporary files
11.5 Data transfer between processes via pipes
11.5.1 Opening pipes and starting the second process
11.5.2 Closing pipes
11.6 Testing for status and errors
12 Standard library functions
12.1 Conversion and classification functions
12.1.1 Classification of characters
12.1.2 Conversion functions
12.2 String handling functions
12.3 Mathematical functions
12.3.1 Arithmetic functions
12.3.2 Transcendental functions
12.3.3 Rounding functions
12.3.4 Trigonometric functions
12.3.5 Normal distribution functions
12.3.6 Pseudo random number generator
12.3.7 Floating-point number manipulation
12.3.8 Error handling for mathematical functions
12.4 Managing data and data structures
12.4.1 Searching, updating and sorting lists
12.4.2 Managing hash tables
12.4.3 Managing binary trees
12.5 Memory operations
12.6 System interfaces with the standard library
12.7 Miscellaneous information
12.8 Protecting programs by passwords
13 Interfaces with the UNIX operating system
13.1 Input/output and file management
13.1.1 Opening and creating files
13.1.1.1 Further processing with standard library functions
13.1.1.2 Converting a file pointer to a file descriptor
13.1.2 Reading and writing
13.1.3 Random access
13.1.4 Support of input/output from/to terminal files
13.1.5 Closing files
13.1.6 File management
13.2 Process management
13.3 Inter-process communication
14 Programming style
15 Operating the programming environment
15.1 Creating source files
15.1.1 Beautifying source programs
15.1.2 Cross-reference lists of source programs
15.1.3 Control flow charts of source programs
15.2 Compiling and linking C programs
15.3 Executing programs and listing files
16 Testing C programs
16.1 Verifying C programs using lint
16.2 Module testing
16.3 Debugging using the symbolic debugger sdb
16.4 Debugging using the preprocessor
16.4.1 Interrupting execution
16.4.2 Conditional interruption of execution
16.4.3 Displaying and changing values
16.4.4 Skipping statements
16.4.5 Displaying loop calls with loop counters
16.4.6 Displaying the calling sequence of functions
17 Error messages
A1 Appendix 1: Summary of statements
A2 Appendix 2: Summary of operators
A3 Appendix 3: Summary of functions
A3.1 Input/output functions
A3.2 Other standard library functions
A4 Appendix 4: ASCII code table
A5 Appendix 5: Index