A Little C Primer
A Little C Primer
Contents
1 Tools For Programming
2 Table of Contents
2.1 Introduction to C; Functions; Control Constructs
2.2 C Variables, Operators & Preprocessor Directives
2.3 C Input & Output
2.4 C Library Functions & Other Comments
2.5 C Quick Reference
2.6 Comments and Revision History
3 Resources and Licensing
This document is a quick introduction to the C programming language. It is written by a novice, and is intended
for use by a novice. However, it does assume familiarity with a programming language.
The C programming language is a "middle-level" language. It provides low-level programming capability at the
expense of some user-friendliness. Cynics tend to claim that C combines the flexibility and power of assembly
language with the user-friendliness of high-level language, but experience programmers find that the limited set
of keywords and the use of pointers allows for fast and elegant programming solutions. C first rose to
popularity with the growth of UNIX, and has been used creating the Windows operating system from its
earliest versions. It is also used in microcontrollers and super-computers.
The original implementations of C were defined as described in the classic reference, THE C
PROGRAMMING LANGUAGE, authored by Brian Kernighan and Dennis Ritchie. This definition left a few
things to be desired, and the American National Standards Institute (ANSI) formed a group in the 1980s to
create a complete specification. The result was "ANSI C", which is the focus of this document.
When most people start to program in C, the first question they ask is "Where are the windows that I see in MS
Word?" It's only natural in a graphics dominated computer world to want to create a graphical interface for your
program. The easiest way to write a Windows "style" program in C is by downloading Visual C++ (from
Microsoft). This IDE (Integrated Development Environment) allows you to call the GUI (Graphical User
Interface) provided by Microsoft where all the buttons, windows, dialog boxes, etc are already designed and
ready for use in your program. If you are just starting out then Microsoft provides a free version of Visual C++
with features and functionality that almost matches the professional version.
Though the programming examples given in this book are not GUI based you can still use Visual C++ to
compile them. It's also a good idea to learn to create simple, command-line programs before moving on to
GUIs. Please note that there are many free C and C++ compilers and coding tools offered by companies other
than Microsoft. If you wish to try another IDE, forums and freeware sites are ideal places to find out about
these.
Table of Contents
Introduction to C; Functions; C ontrol Constructs
An Introductory C Program
C Functions in Detail
C Control Constructs
C Math Library
C Standard Utility Library & Time Library
The C sprintf Function
C String Function Library
C Character Class Test Library
C Command Line Arguments
Pointers to C Functions
C Dynamic Memory Allocation & Deallocation
Common Programming Problems in C
C Quick Reference
C Quick Reference