标准C程序设计(第4版)(大学计算机教育国外著名教材系列)(Programming in ANSI C)

分類: 图书,教材教辅与参考书,大学,计算机专业,
品牌: 特尼博姆
基本信息·出版社:清华大学出版社
·页码:543 页
·出版日期:2009年
·ISBN:9787302197959
·条形码:9787302197959
·包装版本:1(影印版)
·装帧:平装
·开本:16
·正文语种:中文
·丛书名:大学计算机教育国外著名教材系列
·外文书名:Programming in ANSI C
产品信息有问题吗?请帮我们更新产品信息。
内容简介《标准C程序设计》是印度各大学使用最广的C语言程序设计教材之一。
本书旨在教授读者如何使用C语言进行程序设计。全书贯彻了“用示例学习”的概念。在深入介绍了C语言的每个特性之后,给出了一个完整的示例程序,用于演示说明其应用。每章末尾的“案例学习”不仅介绍了把C语言的特性集成在一起的常用方法,而且还显示了它在实际生活中的应用。最后一章介绍了开发高效、无错误的C程序的一些指导原则。
本书在前一版的基础上增加介绍了C99的一些新特性,并增加了不少复习题和项目设计题,而且在附录IV中给出了4个完整的应用程序开发示例,使得本书的实际应用性更强。
编辑推荐《标准C程序设计》第3版融入了过去10年中采用本书的学生和老师的很多反馈意见。本版的特点包括:
l 基于最新的C语言标准。
l 在本书的最后给出了4个完整的应用程序开发示例。
l 扩展讨论了C的指针。
l 每章后面的“谨记”一节给出了很有用的编程提示以及可能容易出错的问题。
l 20多个真实的开发案例,展示了C程序的设计过程。
l 80多个程序设计范例,向读者阐述了良好程序设计的基本原则。
l 还有200多个复习题和150多个项目设计题。
总之,本书的语言简洁易懂,示例非常丰富且具有很强的实际指导意义,是一本很好的C语言程序设计的教材。
目录
第1章 C语言概述
第2章 常量、变量及数据类型
第3章 运算符与表达式
第4章 输入输出操作管理
第5章 判断与分支
第6章 判断与循环
第7章 数组
第8章 字符数组与字符串
第9章 自定义函数
第10章 结构与联合
第11章 指针
第12章 文件管理
第13章 动态内存分配与链表
第14章 预处理器
第15章 C程序开发指导原则
附录I 位级程序设计
附录II
附录III
附录IV 项目设计
附录V C99的特性
Preface to the Fourth Edition xi
lace to the Fourth Edition xi
1 Overview of C 1
1.1 History of C 1
1.2 Importance of C 3
1.3 Sample Program 1: Printing a Message 3
1.4 Sample Program 2: Adding Two Numbers 6
1.5 Sample Program 3: Interest Calculation 8
1.6 Sample Program 4: Use of Subroutines 10
1.7 Sample Program 5: Use of Math Functions 11
1.8 Basic Structure of C Programs 12
1.9 Programming Style 14
1.10 Executing a 'C' Program 14
1.11 Unix System 16
1.12 Ms-Dos System 18
Review Questions 19
Programming Exercises 20
2 Constants, Variables, and Data Types 23
2.1 Introduction 23
2.2 Character Set 23
2.3 C Tokens 25
2.4 KeyWords and identifiers 25
y words and ldentiners 25
2.5 Constants 26
2.6 Variables 30
2.7 Data Types 31
~'
2.8 Declaration of Variables 34
2.9 Declaration of Storage Class 37
2.10 Assigning Values to Variables 38
2.11 Defining Symbolic Constants 44
2.12 Declaring a Variable as Constant 45
2.13 Declaring a Variable as Volatile 45
Vi Contents
2.14 Overflow and Underflow of Data 46
Review Questions 49
Programming Exercises 51
3 Operators and Expressions 52
3.1 Introduction 52
3.2 Arithmetic Operators 52
3.3 Relational Operators 55
3.4 Logical Operators 57
3.5 Assignment Operators 57
3.6 Increment and Decrement Operators 59
3.7 Conditional Operator 61
3.8 Bitwise Operators 61
3.9 Special Operators 61
3.10 Arithmetic Expressions 63
3.11 Evaluation of Expressions 64
3.12 Precedence of Arithmetic Operators 65
3.13 Some Computational Problems 67
3.14 Type Conversions in Expressions 68
3.15 Operator Precedence and Associativity 72
3.16 Mathematical Functions 74
Review Questions 78
Programming Exercises 81
4 Managing input and Output Operations 84
4.1 Introduction 84
4.2 Reading a Character 85
4.3 Writing a Character 88
4.4 Formatted input 89
4.5 Formatted Output 98
Review Questions 110
Programming Exercises 112
5 Decision Making and Branching 114
5.1 Introduction 114
5.2 Decision Making with iF Statement 114
5.3 Simple iF Statement 115
5.4 The IF.....ELSE Statement 119
5.5 Nesting of IF....ELSE Statements 122
5.6 The ELSE IF Ladder 126
5.7 The Switch Statement 129
5.8 The ?' Operator 133
5.9 The GOTO Statement 136
Review Questions 144
Programming Exercises 148
Contents Vii
6 Decision Making and Looping 152
6.1 Introduction 152
6.2 The WHILE Statement 154
6.3 The DO Statement 157
6.4 The FOR Statement 159
6.5 Jumps in LOOPS 166
6.6 Concise Test Expressions 174
Review Questions 182
Programming Exercises 186
7 Arrays 190
7.1 Introduction 190
7.2 One-dimensional Arrays 192
7.3 Declaration of One-dimensional Arrays 193
7.4 Initialization of One-dimensional Arrays 195
7.5 Two-dimensional Arrays 199
7.6 Initializing Two-dimensional Arrays 204
7.7 Multi-dimensional Arrays 208
7.8 Dynamic Arrays 209
7.9 More about Arrays 209
Review Questions 223
Programming Exercises 225
8 Character Arrays and Strings 229
8.1 Introduction 229
8.2 Declaring and initializing String Variables 230
8.3 Reading Strings from Terminal 231
8.4 Writing Strings to Screen 236
8.5 Arithmetic Operations on Characters 241
8.6 Putting Strings Together 242
8.7 Comparison of Two Strings 244
8.8 String-handling Functions 244
8.9 Table of Strings 250
8.10 Other Features of Strings 252
Review Questions 257
Programming Exercises 259
9 User-defined Functions 262
9.1 Introduction 262
9.2 Need for User-defined Functions 262
9.3 A Multi-function Program 263
9.4 Elements of User-defined Functions 266
9.5 Definition of Functions 267
9.6 Return Values and their Types 269
9.7 Function Calls 270
9.8 Function Declaration 272
Vin Contents
9.9 Category of Functions 274
9.10 No Arguments and no Return Values 274
9.11 Arguments but no Return Values 277
9.12 Arguments with Return Values 280
9.13 No Arguments but Returns a Value 284
9.14 Functions that Return Multiple Values 285
9.15 Nesting of Functions 286
9.16 Recursion 288
9.17 Passing Arrays to Functions 289
9.18 Passing Strings to Functions 294
9.19 The Scope, Visibility and Lifetime of Variables 295
9.20 Multifile Programs 305
Review Questions 311
Programming Exercises 315
10 Structures and Unions 317
10.1 Introduction 317
10.2 Defining a Structure 317
10.3 Declaring Structure Variables 319
10.4 Accessing Structure Members 321
10.5 Structure initialization 322
10.6 Copying and Comparing Structure Variables 324
10.7 Operations on individual Members 326
10.8 Arrays of Structures 327
10.9 Arrays within Structures 329
10.10 Structures within Structures 331
10.11 Structures and Functions 333
10.12 Unions 335
10.13 Size of Structures 337
10.14 Bit Fields 337
Review Questions 344
Programming Exercises 348
11 Pointers 351
11.1 Introduction 351
11.2 Understanding Pointers 351
11.3 Accessing the Address of a Variable 354
11.4 Declaring Pointer Variables 355
11.5 Initialization of Pointer Variables 356
11.6 Accessing a Variable through its Pointer 358
11.7 Chain of Pointers 360
11.8 Pointer Expressions 361
11.9 Pointer increments and Scale Factor 362
11.10 Pointers and Arrays 364
11.11 Pointers and Character Strings 367
11.12 Array of Pointers 369
Contents iX
11.13 Pointers as Function Arguments 370
11.14 Functions Returning Pointers 373
11.15 Pointers to Functions 373
11.16 Pointers and Structures 376
11.17 Troubles with Pointers 379
Review Questions 385
Programming Exercises 388
12 File Management in C 389
12.1 Introduction 389
12.2 Defining and Opening a File 390
12.3 Closing a File 391
12.4 Input/Output Operations on Files 392
12.5 Error Handling During I/O Operations 398
12.6 Random Access to Files 400
12.7 Command Line Arguments 405
Review Questions 408
Programming Exercises 409
13 Dynamic Memory Allocation and Linked Lists 411
13.1 Introduction 411
13.2 Dynamic Memory Allocation 411
13.3 Allocating a Block of Memory: MALLOC 413
13.4 Allocating Multiple Blocks of Memory: CALLOC 415
13.5 Releasing the Used Space: Free 415
13.6 Altering the Size of a Block' REALLOC 416
13.7 Concepts of Linked Lists 417
13.8 Advantages of Linked Lists 420
13.9 Types of Linked Lists 421
13.10 Pointers Revisited 422
13.11 Creating a Linked List 424
13.12 Inserting an item 428
13.13 Deleting an item 431
13.14 Application of Linked Lists 433
Review Questions 440
Programming Exercises 442
14 The Preprocessor 444
14.1 Introduction 444
14.2 Macro Substitution 445
14.3 File inclusion 449
14.4 Compiler Control Directives 450
14.5 ANSI Additions 453
Review Questions 456
Programming Exercises 457
X Contents
15 Developing a C Program: Some Guidelines 458
15.1 Introduction 458
15.2 Program Design 458
15.3 Program Coding 460
15.4 Common Programming Errors 462
15.5 Program Testing and Debugging 469
15.6 Program Efficiency 471
Review Questions 472
Appendix i: Bit-level Programming 474
Appendix II: ASCll Values of Characters 480
Appendix ill: ANSI C Library Functions 482
Appendix IV: Projects 486
Appendix V: C99 Features 537
Bibliography 545
……[看更多目录]
序言About the Author
E Balagurusamy, former Vice Chancellor, Anna University, Chennai, is currently
Member, Union Public Service Commission, New Delhi. He is a teacher, trainer, and consultant
.
in the fields of information TechnologV and Management. He holds an ME (Hons) in
Electri.y and Management. He holds an ME (Hons) in
Electrical Engineering and Ph.D. in Systems Engineering from the indian institute of Technology,
Roorkee. His areas of interest include Object-Oriented Software Engineering, Electronic
.ect-Oriented Software Engineering, Electronic
Business, Technology Management, Business Process Re-engineering, and Total Quality
Management.
A prolific writer, he has authored a large number of research papers and several books.
His best selling books, among others, include:
. Programming in C#
. Programming in Java, 3/e
. Object-Oriented Programming with C++, 3/e
.ect-Oriented Programming with C++, 3/e
. Programming in BASIC, 3/e
. Numerical Methods
. Reliability Engineering
y Engineering
A recipient of numerous honours and awards, he has been listed in the Directory of Who's
Who of intellectuals and in the Directory of Distinguished Leaders in Education.
Preface to the Fourth
Edition
Cis a powerful, flexible, portable and elegantly structured programming language. Since
C combines the features of high-level language with the elements of the assembler, it is
suitable for both systems and applications programming. It is undoubtedly the most widely
J .terns and applications programming. It is undoubtedly the most widely
used general-purpose language today.
Since its standardization in 1989, C has undergone a series of changes and improvements
.fi,,,n,n,,,m 1'l - if',, - 1
in order to enhance the usefulness of the language. The version that incorDorates the new
o or porates the new
features is now referred to as C99. The fourth edition of ANSI C has been thoroughly revised
and enlarged not only to incorporate the numerous suggestions received both from teachers
and students across the country but also to highlight the enhancements and new features
added by C99.
J u99.
Organization of the book
The book starts with an overview of C, which talks about the history of C, basic structure of
C programs and their execution. The second chapter discusses how to declare the constants,
variables and data types. The third chapter describes the built-in operators and how to build
ypes. The third chapter describes the built-in operators and how to build
..
expressions using them. The fourth chapter details the input and output operations.
Deci.1.111..1 .1.1 ~ fry n j ~ 11if.Ill 1
sion making and branching is discussed in the fifth chapter, which talks about the if-else,
o and branching is discussed in the fifth chapter, which talks about the if-else,
switch and goto statements. Further, decision making and looping is discussed in Chapter
.1.11. 111 - "l^111,n 1llJ
six. which covers while. do and for fooDs. Arrays and ordered arrangement of data elements
, which covers while, do and for loops. Arrays and ordered arrangement of data elements
.
are important to any programming language and have been covered in chapters seven and
eight. Strings are also covered in Chapter eight. Chapters nine and ten are on functions,
structures and unions. Pointers, perhaps the most difficult part of C to understand, is
covered in Chapter eleven in the most user-friendly manner. Chapters twelve and thirteen
are on file management and dynamic memory allocation respectively. Chapter fourteen deals
with the preprocessor, and finally Chapter 15 is on developing a C program, which provides
..,l,11. I - 11,Inm 11'l .1 1
an insight on how to Droceed with develODment of a Drogram. The above organization would
.lit on how to proceed with development of a program. The above organization would
help the students in understanding C better if followed appropriately.
Xii Preface
New to the edition
The content has been revised keeping the updates which have taken placed in the field of C
programming and the present day syllabus needs. As always, the concept of 'learning by
example' has been stressed throughout the book. Each major feature of the language is
treated in depth followed by a complete program example to illustrate its use. The sample
programs are meant to be both simple and educational. Two new projects are added at the
end of the book for students to go through and try on their own.
Each chapter includes a section at the beginning to introduce the topic in a proper
perspective. It also provides a quick look into the features that are discussed in the chapter.
Wherever necessary, pictorial descriptions of concepts are included to improve clarity and to
facilitate better understanding. Language tips and other special considerations are
highlighted as notes wherever essential. In order to make the book more user-friendly, we have
incorporated the following key features.
O Codes with comments are provided throughout the book to illustrate how the
various features of the language are put together to accomplish specified tasks.
O SuPPlementrrry imp~rrtion abed notes that complement but stand apart from the
general text have been included in boxes.
O Guidelines for developing efficient C programs are given in the last chapter, together
with a list of some common mistookes that a less experienced C programmer could
make.
O Cause steadies at the end of the chapters illustrate common ways C features are put
together and also show real-life applications.
O The Joest Remember section at the end of the chapters lists out helpful hints and
possible problem areas.
O Numerous chapter-end questions and exercises provide ample opportunities to the
readers to review the concepts learned and to practice their applications.
O Progrrrmming projects discussed in the appendix give insight on how to integrate
the various features of C when handling large programs.
Supplementary Mntertul
With this revision we have tried to enhance the online learning center too. The
supplementary material would include the following:
For the instructor
Q Solutions to the debugging exercises
For the Student
Q Exclusive project for implementation with code, step-by-step description and user
manual
Q Code for the two projects (given in the book)
U Two mini projects
Q Reading material on C
This book is designed for all those who wish to be C programmers, regardless of their past
knowledge and experience in programming. It explains in a simple and easy-to-understand
style the what, why and how of programming with ANSI C.
文摘插图:

Use the size of operator to determine the size of a linked list. When using memory allocation functions malloc and calloc,test for a NULL pointer return value.Print appropriate message if the memory allocation fails.
Never call memory allocation functions with a zero size. Release the dynamically allocated memory when it is no longer required to avoid any possible“memory leak".
Using free function to release the memory not allocated dynamically with malloc or calloc is an error.
Use of a invalid pointer with free may cause problems and,sometimes, system crash.
Using a pointer after its memory has been released is an error.
It is anerrortoassignthe return value from ma Hoc or calloc to anything other than a pointer.
It is a logic error to set a pointer to NULL before the node has been released.The node is irretrieva6ly lost.
It is an error to declare a self-referential structure without a structure tag. It is an error to release individually the elements of an array created with Calloc. It is a logic error to fail to set the link filed in the last node to null.
1.Insertion in a Sorted List
The task of inserting a value into the current location in a sorted linked list involves two operations:
1.Finding the node before which the new node has to be inserted .We call this node as ‘Key node’.
2.Creating a new node with the value to be inserted and inserting the new node by manipulating pointers appropriately.
In order to illustrate the process of insertion,we use a sorted linked list created by th I create function discussed in Exemple 13.3.Figure 13.11 shows a complete program tha l creates a list (using sorted input data)and then inserts a given value into the correct plan using function insert.