151. C Programming
Rev. 1.0
This course provides students with a comprehensive study of the C
programming language. Classroom lectures stress the strengths of C, which
provide programmers with the means of writing efficient, maintainable, and
portable code. The lectures are supplemented with non-trivial lab exercises.
LEARNING OBJECTIVES
·
Gain a working knowledge of C programming
·
Learn how to write modular, efficient and readable C
programs
·
Utilize pointers to efficiently solve problems
·
Use functions from the portable C library.
Course Duration: 5
days
Prerequisites:
Experience with a programming language or an assembly language
1. Getting
Started
Background
Sample program
Components of a C program
Data types
Naming conventions for variables
Printing and initializing variables
Defining arrays
2. Functions
and Operators
Functions
Invoking functions
Elementary operators
The operator= operators
The conditional operator
Increment and decrement operators
3. Control
Flow Constructs
if statement
if else statement
while loop
for loop
Endless loops
do while loop
break and continue statements
switch statement
else if
4. The
C Preprocessor
#define
Writing macros
#include
#ifdef
#ifndef
5. Simple
I/O
Character i/o
Handling end of file
Simple i/o examples
Redirecting standard I/O
i/o with character arrays
6. More
On Functions
Function declarations
Returning a value or not
Function prototypes
Arguments and parameters
Organization of C source files
An extended example
Main function
The gets function
The strcmp function
The check function
The atoi function
The average function
7. Bit
Manipulation
Defining the problem space
Readability aids
Bit wise operators
Bit wise functions
Circular shifts
8. Strings
Fundamental concepts
Aggregate operations
String functions
9. Higher
Dimensional Arrays
Array dimensions
An array as an argument to a function
Arrays of strings
10. Separate Compilation
Compiling over several files
Function scope
File scope
Program scope
Local static
resister and extern
Object files
Libraries
The C loader
Header files
11. Pointers (Part I)
Fundamental concepts
Pointer operators and operations
Changing an argument with a function call
Pointer arithmetic
Traversing arrays with a pointer
Traversing strings with a pointer
String functions with pointers
Relationship between array and pointer
The pointer notation *p++
12. Pointers (Part II)
Dynamic storage allocation - malloc
Functions returning a pointer
Initialization of pointers
gets - A Function returning a pointer
An array of character pointers
Pointer to pointer
Command line arguments (CLA) - rationale
CLA: Pointer expressions
The environment pointer
Accessing characters on the command line
Practice with pointers
Changing a pointer through a function call
Pointer to a function
Uses of pointers to functions
13. Structures
Fundamental concepts
Describing a structure
Creating structures
Operations on structures
Functions returning structures
Passing structures to functions
Pointers to structures
Making sense of the p -> member notation
Structures vs structure pointers
Array of structures
Functions returning pointer to structure
14. Structure Related Items
typedef - New name for an existing type
typedef with structures
Header files for structure applications
Bit fields
Unions
Non-homogeneous arrays
Enumeration types
15. File I/O
System calls vs library calls
Opening disk files
Access modes
Errors in opening files
i/o library calls
Example: copying a file
Character input vs line input
Motivation for the scanf function
scanf and variants
printf variants
Closing files fclose
Servicing errors – errno
16. Information About Files
The stat function
File existence
Telling time - time
ctime
localtime
17. Binary I/O With
Structures
A data base application
the main function
the menu function
create_db function - fwrite
print_db function - fread
fseek
retrieve_db function
fflush and ftell
18. Useful Library Functions
strstr - Is one string a substring
strchr, strrchr - Is a char in a string
system - Execute a command line command
strtok - Tokenize a string
strspn, strcspn - Verify string content
Math functions
Character testing functions
Appendix. Reference Tables
Important header files
printf formats
C reserved words
Conversion
Precedence charts
System Requirements
The course is designed to be delivered in any environment supporting
a C compiler.