书籍详情
C语言程序设计
作者:(美)stephen G.Kochan著
出版社:人民邮电出版社
出版时间:2006-05-01
ISBN:9787115147639
定价:¥55.00
购买这本书可以去
内容简介
本书主要讲解如何用C语言编程。书中涵盖了C语言的所有特性,包括ANSI C99标准最新增加的特性。本书通过示例讲解C语言,使用完整的程序来阐释每个新概念,而且对所有C函数都提供了一步一步的说明。此外,每章结尾都配有习题,附录还提供了详细的C语言的小结和标准C语言库,便于快速参考。读者既可从本书中学到语言的基础,又可以学到好的编程实践。 无论是课堂讲解还是自学,本书都是理想的C语言教材。
作者简介
StephenG.Kochan有20多年使用C语言进行软件开发的经验,是多本畅销的C语言和Unix方面经典图书的作者,包括ProgramminginANSIC、TopicsinCProgram-ming、ExploringtheUnixSystem、UnixShellProgramming和UnixSystemSecurity,最近还出版了ProgramminginObjective-C。他曾是AT&T贝尔实验室的软件顾问,主要负责开发和讲授UNIX和C程序设计方面的课程。
目录
Introduction1
Some Fundamentals5
Programming5
Higher-Level Languages6
Operating Systems6
Compiling Programs7
Integrated Development Environments10
Language Interpreters10
Compiling and Running Your First
Program11
CompilingYour Program11
P,-unningYour Program12
UnderstandingYour First Program13
Displaying theValues of Variables15
Comments17
Exercises19
Variables, Data Types, and Arithmetic
Expressions21
Working with Variables21
Understanding Data Types and Constants23
The Basic Integer Type ~ne23
The Floating NumberType float24
The Extended Precision Type double25
The Single Character Type char25
The Boolean DataType Bool26
Type Specifiers: long, long long, short,
unsigned, and signed28
Working with Arithmetic Expressions30
Integer Arithmetic and the Unary Minus
Operator33
The Modulus Operator35
Integer and Floating-Point Conversions36
Combining Operations with Assignment: The
Assignment Operators38
Types Complex and Imaginary39
Exercises40
Program Looping43
The for Statement44
Relational Operators46
Aligning Output50
Program Input51
Nested for Loops53
for Loop Variants54
The while Statement56
The do Statement60
The break Statement62
The continue Statement62
Exercises63
Making Decisions65
The if Statement65
The if-else Construct69
Compound Relational Tests72
Nested if Statements75
The else if Construct76
The switch Statement84
Boolean Variables87
The Conditional Operator91
Exercises93
Working with Arrays95
Defining an Array96
Using Array Elements as Counters100
Generating Fibonacci Numbers103
Using an Array to Generate Prime Numbers
104
Initializing Arrays106
Character Arrays108
Base Conversion Using Arrays109
The const Qualifier111
Multidimensional Arrays113
Variable-Length Arrays115
Exercises117
Working with Functions119
Defining a Function119
Arguments and LocalVariables122
Function Prototype Declaration124
Automatic LocalVariables124
Returning Function Results126
Functions Calling Functions Calling...131
Declaring Return Types and Argument Types1
134
Checking Function Arguments135
Top-Down Programming137
Functions and Arrays137
Assignment Operators142
Sorting Arrays143
Multidimensional Arrays146
GlobalVariables152
Automatic and Static Variables156
Recursive Functions159
Exercises162
Working with Structures165
A Structure for Storing the Date166
Using Structures in Expressions168
Functions and Structures171
A Structure for Storing theTime177
Initializing Structures180
Compound Literals181
Arrays of Structures182
Structures Containing Structures185
Structures Containing Arrays187
Structure Variants190
Exercises191
10Character Strings195
Arrays of Characters196
Variable-Length Character Strings198
Initializing and Displaying Character
Strings201
Testing Two Character Strings for Equality204
Inputting Character Strings206
Single-Character Input208
The Null String213
Escape Characters216
More on Constant Strings218
Character Strings, Structures, and Arrays219
A Better Search Method222
Character Operations227-
Exercises230
1Pointers235
Defining a PointerVariable.235
Using Pointers in Expressions239
Working with Pointers and Structures240
Structures Containing Pointers243
Linked Lists244
The Keyword const and Pointers253
Pointers and Functions254
Pointers and Arrays259
A Slight Digression About Program
Optimization263
Is It an Array or Is It a Pointer?264
Pointers to Character Strings266
Constant Character Strings and Pointers26;
The Increment and Decrement Operators
Revisited268
Operations on Pointers272
Pointers to Functions273
Pointers and Memory Addresses274
Exercises276
12Operations on Bits279
Bit Operators280
The Bitwise AND Operator281
The Bitwise Inclusive-OR Operator283
The Bitwise Exclusive-OR Operator284
The Ones Complement Operator285
The Left Shift Operator287
The Right Shift Operator287
A Shift Function288
Rotating Bits290
Bit Fields292
Exercises297
13The Preprocessor299
The #define Statement299
Program Extendability303
Program Portability305
More Advanced Types of Definitions306
The # Operator312
The ## Operator313
The #include Statement313
System Include Files316
Conditional Compilation316
The #ifdef, #endif, #else, and #ifndef
Statements316
The #if and #elif Preprocessor
Statements318
The #undef Statement319
Exercises320
14 More on Data Types321
Enumerated Data Types321
The typedef Statement325
Data Type Conversions327
Sign Extension329
Argument Conversion329
Exercises330
15Working with Larger Programs333
DividingYour Program into Multiple Files333
Compiling Multiple Source Files from the
Command Line334
Communication Between Modules336
External Variables336
Static Versus ExternVariables and
Functions339
Using Header Files Effectively341
Other Utilities for Working with Larger
Programs342
The make Utility343
The cvs Utility344
Unix Utilities: at, grep, sed, and so on345
16 Input and Output Operations in C347
Character I/O: getchar and putchar348
Formatted I/O: printf and scanf348
The printf Function348
The scanf Function355
Input and Output Operations with Files359
Redirecting I/O to a File359
End of File361
Special Functions for Working with Files363
The fopen Function363
The getc and putc Functions365
The fclose Function365
The feof Function367
The fprintf and fscanf Functions368
The fgets and fputs Functions368
stdin, stdout, and stderr369
The exit Function370
Renaming and Removing Files371
Exercises371
17Miscellaneous and Advanced Features373
Miscellaneous Language Statements373
The goto Statement373
The null Statement374
Working with Unions375
The Comma Operator378
Type Qualifiers378
The register Qualifier378
The volatile Qualifier379
The restrict Qualifier379
Command-Line Arguments380
Dynamic Memory Allocation383
The calloc and malloc Functions384
The sizeof Operator385
The free Function387
18 Debugging Programs389
Debugging with the Preprocessor389
Debugging Programs with gdb395
Working with Variables398
Source File Display399
Controlling Program Execution400
Getting a StackTrace405
Calling Functions and Setting Arrays and
Structures405
Getting Help with gdb Commands406
Odds and Ends408
19Object-Oriented Programming411
What Is an Object Anyway?411
Instances and Methods412
Writing a C Program to Work with Fractions413
Defining an Objective-C Class to Work with
Fractions414
Defining a C++ Class toWork with Fractions419
. Defining a C# Class to Work with Fractions422
A C Language Summary425
1.0 Digraphs and Identifiers425
1.1 Digraph Characters425
1.2 Identifiers425
2.0 Comments426
3.0 Constants427
3.1 Integer Constants427
3.2 Floating-Point Constants427
3.3 Character Contants428
3.4 Character String Constants429
3.5 Enumeration Constants430
4.0 Data Types and Declarations430
4.1 Declarations430
4.2 Basic Data Types430
4.3 Derived DataTypes432
4.4 Enumerated Data Types438
4.5The typedef Statement438
4.6 Type Modifiers const, volatile, and
restrict439
5.0 Expressions439
5.1 Summary of C Operators440
5.2 Constant Expressions442
5.3 Arithmetic Operators443
5.4 Logical Operators444
5.5 Relational Operators444
5.6 Bitwise Operators445
5.7 Increment and Decrement Operators445
5.8 Assignment Operators446
5.9 Conditional Operators446
5.10 Type Cast Operator446
5.11 sizeof Operator447
5.12 Comma Operator447
5.13 Basic Operations with Arrays447
5.14 Basic Operations with Structures448
5.15 Basic Operations with Pointers448
5.16 Compound Literals450
5.17 Conversion of Basic DataTypes451
6.0 Storage Classes and Scope452
6.1 Functions452
6.2 Variables452
7.0 Functions454
7.1 Function Definition454
7.2 Function Call455
7.3 Function Pointers456
8.0 Statements456
8.1 Compound Statements456
8.2 The break Statement456
8.3 The continue Statement457
8.4 The do Statement457
8.5 The for Statement457
8.6The goto Statement458
8.7The if Statement458
8.8 The null Statement458
8.9 The return Statement459
8.10 The switch Statement459
8.11 The while Statement460
9.0 The Preprocessor460
9.1 Trigraph Sequences460
9.2 Preprocessor Directives461
9.3 Predefined Identifiers466
BThe Standard C Library467
Standard Header Files467
<stddef .h>467
<limits.h>468
<stdbool. h>469
<float.h>469
<stdint.h>469
String Functions470
Memory Functions472
Character Functions473
I/O Functions473
In-Memory Format Conversion Functions478
String-to-Number Conversion479
Dynamic Memory Allocation Functions481
Math Functions482
Complex Arithmetic488
General Utility Functions490
CCompiling Programs with ~cc493
General Command Format493
Command-Line Options494
DCommon Programming Mistakes497
E Resources501
Answers to Exercises, Errata, etc.501
The C Programming Language501
Books501
Web Sites502
Newsgroups502
C Compilers and Integrated Development
Environments502
gcc502
MinGW502
CygWin502
Visual Studio503
CodeWarrior503
Kylix503
Miscellaneous503
Object-Oriented Pmgranming503
The C++ Language503
The C# Language503
The Objective-C Language503
Development Tools504
Index505
Some Fundamentals5
Programming5
Higher-Level Languages6
Operating Systems6
Compiling Programs7
Integrated Development Environments10
Language Interpreters10
Compiling and Running Your First
Program11
CompilingYour Program11
P,-unningYour Program12
UnderstandingYour First Program13
Displaying theValues of Variables15
Comments17
Exercises19
Variables, Data Types, and Arithmetic
Expressions21
Working with Variables21
Understanding Data Types and Constants23
The Basic Integer Type ~ne23
The Floating NumberType float24
The Extended Precision Type double25
The Single Character Type char25
The Boolean DataType Bool26
Type Specifiers: long, long long, short,
unsigned, and signed28
Working with Arithmetic Expressions30
Integer Arithmetic and the Unary Minus
Operator33
The Modulus Operator35
Integer and Floating-Point Conversions36
Combining Operations with Assignment: The
Assignment Operators38
Types Complex and Imaginary39
Exercises40
Program Looping43
The for Statement44
Relational Operators46
Aligning Output50
Program Input51
Nested for Loops53
for Loop Variants54
The while Statement56
The do Statement60
The break Statement62
The continue Statement62
Exercises63
Making Decisions65
The if Statement65
The if-else Construct69
Compound Relational Tests72
Nested if Statements75
The else if Construct76
The switch Statement84
Boolean Variables87
The Conditional Operator91
Exercises93
Working with Arrays95
Defining an Array96
Using Array Elements as Counters100
Generating Fibonacci Numbers103
Using an Array to Generate Prime Numbers
104
Initializing Arrays106
Character Arrays108
Base Conversion Using Arrays109
The const Qualifier111
Multidimensional Arrays113
Variable-Length Arrays115
Exercises117
Working with Functions119
Defining a Function119
Arguments and LocalVariables122
Function Prototype Declaration124
Automatic LocalVariables124
Returning Function Results126
Functions Calling Functions Calling...131
Declaring Return Types and Argument Types1
134
Checking Function Arguments135
Top-Down Programming137
Functions and Arrays137
Assignment Operators142
Sorting Arrays143
Multidimensional Arrays146
GlobalVariables152
Automatic and Static Variables156
Recursive Functions159
Exercises162
Working with Structures165
A Structure for Storing the Date166
Using Structures in Expressions168
Functions and Structures171
A Structure for Storing theTime177
Initializing Structures180
Compound Literals181
Arrays of Structures182
Structures Containing Structures185
Structures Containing Arrays187
Structure Variants190
Exercises191
10Character Strings195
Arrays of Characters196
Variable-Length Character Strings198
Initializing and Displaying Character
Strings201
Testing Two Character Strings for Equality204
Inputting Character Strings206
Single-Character Input208
The Null String213
Escape Characters216
More on Constant Strings218
Character Strings, Structures, and Arrays219
A Better Search Method222
Character Operations227-
Exercises230
1Pointers235
Defining a PointerVariable.235
Using Pointers in Expressions239
Working with Pointers and Structures240
Structures Containing Pointers243
Linked Lists244
The Keyword const and Pointers253
Pointers and Functions254
Pointers and Arrays259
A Slight Digression About Program
Optimization263
Is It an Array or Is It a Pointer?264
Pointers to Character Strings266
Constant Character Strings and Pointers26;
The Increment and Decrement Operators
Revisited268
Operations on Pointers272
Pointers to Functions273
Pointers and Memory Addresses274
Exercises276
12Operations on Bits279
Bit Operators280
The Bitwise AND Operator281
The Bitwise Inclusive-OR Operator283
The Bitwise Exclusive-OR Operator284
The Ones Complement Operator285
The Left Shift Operator287
The Right Shift Operator287
A Shift Function288
Rotating Bits290
Bit Fields292
Exercises297
13The Preprocessor299
The #define Statement299
Program Extendability303
Program Portability305
More Advanced Types of Definitions306
The # Operator312
The ## Operator313
The #include Statement313
System Include Files316
Conditional Compilation316
The #ifdef, #endif, #else, and #ifndef
Statements316
The #if and #elif Preprocessor
Statements318
The #undef Statement319
Exercises320
14 More on Data Types321
Enumerated Data Types321
The typedef Statement325
Data Type Conversions327
Sign Extension329
Argument Conversion329
Exercises330
15Working with Larger Programs333
DividingYour Program into Multiple Files333
Compiling Multiple Source Files from the
Command Line334
Communication Between Modules336
External Variables336
Static Versus ExternVariables and
Functions339
Using Header Files Effectively341
Other Utilities for Working with Larger
Programs342
The make Utility343
The cvs Utility344
Unix Utilities: at, grep, sed, and so on345
16 Input and Output Operations in C347
Character I/O: getchar and putchar348
Formatted I/O: printf and scanf348
The printf Function348
The scanf Function355
Input and Output Operations with Files359
Redirecting I/O to a File359
End of File361
Special Functions for Working with Files363
The fopen Function363
The getc and putc Functions365
The fclose Function365
The feof Function367
The fprintf and fscanf Functions368
The fgets and fputs Functions368
stdin, stdout, and stderr369
The exit Function370
Renaming and Removing Files371
Exercises371
17Miscellaneous and Advanced Features373
Miscellaneous Language Statements373
The goto Statement373
The null Statement374
Working with Unions375
The Comma Operator378
Type Qualifiers378
The register Qualifier378
The volatile Qualifier379
The restrict Qualifier379
Command-Line Arguments380
Dynamic Memory Allocation383
The calloc and malloc Functions384
The sizeof Operator385
The free Function387
18 Debugging Programs389
Debugging with the Preprocessor389
Debugging Programs with gdb395
Working with Variables398
Source File Display399
Controlling Program Execution400
Getting a StackTrace405
Calling Functions and Setting Arrays and
Structures405
Getting Help with gdb Commands406
Odds and Ends408
19Object-Oriented Programming411
What Is an Object Anyway?411
Instances and Methods412
Writing a C Program to Work with Fractions413
Defining an Objective-C Class to Work with
Fractions414
Defining a C++ Class toWork with Fractions419
. Defining a C# Class to Work with Fractions422
A C Language Summary425
1.0 Digraphs and Identifiers425
1.1 Digraph Characters425
1.2 Identifiers425
2.0 Comments426
3.0 Constants427
3.1 Integer Constants427
3.2 Floating-Point Constants427
3.3 Character Contants428
3.4 Character String Constants429
3.5 Enumeration Constants430
4.0 Data Types and Declarations430
4.1 Declarations430
4.2 Basic Data Types430
4.3 Derived DataTypes432
4.4 Enumerated Data Types438
4.5The typedef Statement438
4.6 Type Modifiers const, volatile, and
restrict439
5.0 Expressions439
5.1 Summary of C Operators440
5.2 Constant Expressions442
5.3 Arithmetic Operators443
5.4 Logical Operators444
5.5 Relational Operators444
5.6 Bitwise Operators445
5.7 Increment and Decrement Operators445
5.8 Assignment Operators446
5.9 Conditional Operators446
5.10 Type Cast Operator446
5.11 sizeof Operator447
5.12 Comma Operator447
5.13 Basic Operations with Arrays447
5.14 Basic Operations with Structures448
5.15 Basic Operations with Pointers448
5.16 Compound Literals450
5.17 Conversion of Basic DataTypes451
6.0 Storage Classes and Scope452
6.1 Functions452
6.2 Variables452
7.0 Functions454
7.1 Function Definition454
7.2 Function Call455
7.3 Function Pointers456
8.0 Statements456
8.1 Compound Statements456
8.2 The break Statement456
8.3 The continue Statement457
8.4 The do Statement457
8.5 The for Statement457
8.6The goto Statement458
8.7The if Statement458
8.8 The null Statement458
8.9 The return Statement459
8.10 The switch Statement459
8.11 The while Statement460
9.0 The Preprocessor460
9.1 Trigraph Sequences460
9.2 Preprocessor Directives461
9.3 Predefined Identifiers466
BThe Standard C Library467
Standard Header Files467
<stddef .h>467
<limits.h>468
<stdbool. h>469
<float.h>469
<stdint.h>469
String Functions470
Memory Functions472
Character Functions473
I/O Functions473
In-Memory Format Conversion Functions478
String-to-Number Conversion479
Dynamic Memory Allocation Functions481
Math Functions482
Complex Arithmetic488
General Utility Functions490
CCompiling Programs with ~cc493
General Command Format493
Command-Line Options494
DCommon Programming Mistakes497
E Resources501
Answers to Exercises, Errata, etc.501
The C Programming Language501
Books501
Web Sites502
Newsgroups502
C Compilers and Integrated Development
Environments502
gcc502
MinGW502
CygWin502
Visual Studio503
CodeWarrior503
Kylix503
Miscellaneous503
Object-Oriented Pmgranming503
The C++ Language503
The C# Language503
The Objective-C Language503
Development Tools504
Index505
猜您喜欢