This book made available by the Internet Archive.
Flagging bits Understanding precedence Summary Making statements Testing expressions Branching switches Looping for a number Looping while true Breaking out of loops Going to labels Summary Employing functions Declaring functions Supplying arguments Calling recursively Placing functions in headers Restricting accessibility Summary 66 68 70 72 74 76 78 80 82 84 90 92 94 96 Pointing to data Accessing data via pointers Doing pointer arithmetic Passing pointers to functions Creating arrays of pointers Pointing to functions Summary 98 100 102 104 106 108 Manipulating strings Reading strings Copying strings Joining strings Finding substrings Validating strings Converting strings Summary 110 112 114 116 118 120 122 Building structures Grouping in a structure Defining type structures Using pointers in structures Pointing to structures Passing structures to functions Grouping in a union Allocating memory Summary 124 126 128 130 132 134 136 138 Producing results Creating a file Reading & writing characters Reading & writing lines Reading & writing entire files Scanning filestreams Reporting errors Getting the date and time Running a timer Generating random numbers Displaying a dialog box Summary 140 142 144 146 148 150 152 154 156 158 160 Reference section ASCII character codes Input & output functions Character test functions String functions Math functions Utility functions Diagnostic functions Argument functions Date & time functions Jump functions Signal functions Limit constants Float constants 162 164 173 174 176 178 180 180 181 184 184 185 186 Index Foreword The examples in this book have been carefully prepared to demonstrate the features of the C programming language. You are encouraged to try out the examples on your own computer to discover the exciting possibilities offered by C programming. The straightforward descriptions should allow you to easily recreate the examples manually or, if you prefer, you can download an archive containing all the C source code by following these easy steps: Open your browser and visit our website at http://www.ineasysteps.com ^ Navigate to the "Resource center" and choose the "Downloads" section Find the "From C Programming in easy steps, 3rd edition" item in the "Source code" list, then click on the link entitled "All code examples" to download the ZIP archive Extract the contents of the ZIP archive to any convenient location on your computer - for easy reference these are arranged in sub-folders whose names match each chapter title in this book. The C source files are named as described in the book and can be found in the appropriate chapter folder of the archive. For example, the comparison.c file described in Chapter 4 is located in the folder named 4-Performing operations
C Source File Edit View Tools Help r*"t Search Getting started Welcome to the world of C.
This chapter demonstrates how to create a Cprogram in text, then how to compile it into executable byteform. 8 Introducing the C language 10 Installing a C compiler 12 Writing a C program 14 Compiling a C program 16 Understanding compilation 18 Summary Introducing the C language Dennis M Ritchie, creator of the C programming language. Don't forget Programs written 20 years ago in C are still just as valid today as they were back then. C is a compact general-purpose computer programming language that was originally developed by Dennis MacAlistair Ritchie for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972. This new programming language was named "C" as it succeeded an earlier programming language named "B" that had been introduced around 1970.
The Unix operating system and virtually all Unix applications are written in the C language. However, C is not limited to a particular platform and programs can be created on any machine that supports C, including those running the Windows platform. The flexibility and portability of C made it verv popular and the language was formalized in 1989 by the American National Standards Institute (ANSI). The ANSI standard unambiguously defined each aspect of C, thereby eliminating previous uncertainty about the precise syntax of the language. ANSI C has become the recognized standard for the C language and is described, and demonstrated by examples, in this book. Why learn C programming? The C language has been around for quite some time and has seen the introduction of newer programming languages like Java, C++, and C#.
Many of these new languages are derived, at least in part, from C - but are much larger in size. The more compact C is better to start out in programming because it's simpler to learn. It is easier to move on to learn the newer languages once the principles of C programming have been grasped. For instance, C++ is an extension of C and can be difficult to learn unless you have mastered C programming first. Despite the extra features available in newer languages C remains popular because it is versatile and efficient. It is used today on a large number of platforms for everything from micro-controllers to the most advanced scientific systems.
Programmers around the world embrace C because it allows them maximum control and efficiency in their programs. .cont'd Standard C libraries ANSI C defines a number of standard libraries that contain tried and tested functions, which can be used in your own C programs. The libraries are contained in "header files" that each have a file extension of ".h". The names of the standard C library header files are listed in the table below with a description of their purpose: Hot tip A function is a piece of code that can be reused repeatedly in a C program. A description of each function in the C library is given in the Reference section starting on page 161. Installing a C compiler Hot tip "GNU" is a recursive acronym for "Gnu's Not Unix" and it is pronounced "gun-new".
C programs are initially created as plain text files, saved with a ".c" file extension. These can be written in any plain text editor such as Windows' Notepad application - no special software is needed. In order to execute a C program it must first be "compiled" into byte code that can be understood by the computer. A C compiler reads the original text version of the program and translates it into a second file, which is in machine-readable executable byte format. If the text program contains any syntax errors these will be reported by the compiler and the executable file will not be built. One of the most popular C compilers is the GNU C Compiler (GCC) that is available free under the terms of the General Public License (GPL).
It is included with almost all distributions of the Linux operating system. The GNU C Compiler is used to compile all the examples in this book into executable byte code. To discover if you already have the GNU C Compiler on your system type gcc -v at a command prompt. If it is available the compiler will respond with version information: Terminal Don't forget