1. Trang chủ
  2. » Khoa Học Tự Nhiên

C primer plus, 4th ed 2002

2,2K 82 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 2.187
Dung lượng 12,05 MB

Nội dung

C Primer Plus, Fourth Edition By Stephen Prata Publisher : Sams Publishing Pub Date : September 19, 2001 Table of ISBN : 0-672-32222-6 • Contents Pages : 960 • Index Copyright PREFACE Approach and Goals Changes in the 4th Edition ABOUT THE AUTHOR ACKNOWLEDGMENTS TELL US WHAT YOU THINK! Chapter 1 Getting Ready Whence C? Why C? Whither C? What Computers Do High-Level Computer Languages and Compilers Using C: Seven Steps Programming Mechanics Language Standards Book Organization Some Conventions Summary Review Questions Programming Exercise Chapter 2 Introducing C A Simple Sample of C The Explanation The Structure of a Simple Program Tips on Making Your Programs Readable Taking Another Step While You're at It…Multiple Functions Debugging Keywords and Reserved Identifiers Key Concepts Summary Review Questions Programming Exercises Chapter 3 Data and C A Sample Program Data Variables and Constants Data: Data-Type Keywords C Data Types Using Data Types Arguments and Pitfalls One More Example Key Concepts Summary Review Questions Programming Exercises Chapter 4 Character Strings and Formatted Input/Output Introductory Program Character Strings: An Introduction Constants and the C Preprocessor Exploring and Exploiting printf() and scanf() Usage Tips Key Concepts Summary Review Questions Programming Exercises Chapter 5 Operators, Expressions, and Statements Introducing Loops Fundamental Operators Some Additional Operators Expressions and Statements Type Conversions Function with Arguments A Sample Program Key Concepts Summary Review Questions Programming Exercises Chapter 6 C Control Statements: Looping An Initial Example The while Statement Which Is Bigger: Using Relational Operators and Expressions Indefinite Loops and Counting Loops The for Loop More Assignment Operators: +=, -=, *=, /=, %= The Comma Operator An Exit-Condition Loop: do while Which Loop? Nested Loops Arrays A Loop Example Using a Function Return Value Key Concepts Summary Review Questions Programming Exercises Chapter 7 C Control Statements: Branching and Jumps The if Statement Adding else to the if Statement Let's Get Logical A Word-Count Program The Conditional Operator: ? Loop Aids: continue and break Multiple Choice: switch and break The goto Statement Key Concepts Summary Review Questions Programming Exercises Chapter 8 Character Input/Output and Input Validation Single-Character I/O: getchar() and putchar() Buffers Terminating Keyboard Input Redirection and Files Creating a Friendlier User Interface Input Validation Menu Browsing Key Concepts Summary Review Questions Programming Exercises Chapter 9 Functions Reviewing Functions ANSI C Function Prototyping Recursion All C Functions Are Created Equal Compiling Programs with Two or More Source Code Files Finding Addresses: The & Operator Altering Variables in the Calling Function Pointers: A First Look Key Concepts Summary Review Questions Programming Exercises Chapter 10 Arrays and Pointers Arrays Multidimensional Arrays Pointers and Arrays Functions, Arrays, and Pointers Pointer Operations Protecting Array Contents Pointers and Multidimensional Arrays Variable-Length Arrays (VLAs) Compound Literals Key Concepts Summary Review Questions Programming Exercises Chapter 11 Character Strings and String Functions Defining Strings Within a Program Character String Arrays and Initialization String Input String Output The Do-It-Yourself Option String Functions A String Example: Sorting Strings The ctype.h Character Functions and Strings Command-Line Arguments String to Number Conversions Key Concepts Summary Review Questions Programming Exercises Chapter 12 Storage Classes, Linkage, and Memory Management Storage Classes A Random Number Function and a Static Variable Roll 'Em ANSI C Type Qualifiers New Places for Old Keywords Key Concepts Summary Review Questions Programming Exercises Chapter 13 File Input/Output Communicating with Files Standard I/O A Simple-Minded File-Condensing Program File I/O: fprintf(), fscanf(), fgets(), and fputs() Adventures in Random Access: fseek() and ftell() Behind the Scenes with Standard I/O Other Standard I/O Functions Key Concepts Summary Review Questions Programming Exercises Chapter 14 Structures and Other Data Forms Sample Problem: Creating an Inventory of Books Setting Up the Structure Declaration Defining a Structure Variable Gaining Access to Structure Members Arrays of Structures Nested Structures Pointers to Structures Telling Functions About Structures Saving the Structure Contents in a File Structures: What Next? Unions: A Quick Look Enumerated Types typedef: A Quick Look Fancy Declarations Functions and Pointers Key Concepts Summary Review Questions Programming Exercises Chapter 15 Bit Fiddling Binary Numbers, Bits, and Bytes Other Bases C's Bitwise Operators Bit Fields Key Concepts Summary Review Questions Programming Exercises Chapter 16 The C Preprocessor and the C Library First Steps Manifest Constants: #define Using Arguments with #define Macro or Function? File Inclusion: #include Other Directives Inline Functions The C Library The Math Library The General Utilities Library The Assert Library memcpy() and memmove() from the string.h Library Variable Arguments: stdarg.h Key Concepts Summary Review Questions Programming Exercises Chapter 17 Advanced Data Representation Exploring Data Representation Beyond the Array to the Linked List Abstract Data Types (ADTs) Getting Queued with an ADT Simulating with a Queue The Linked List Versus the Array Binary Search Trees Other Directions Key Concepts Summary Review Questions Programming Exercises Appendix A Answers to the Review Questions Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Appendix B Reference Section Section IAdditional Reading Section IIC Operators Logical Operators Sign Operators Section IIIBasic Types and Storage Classes Summary: Qualifiers Section IVExpressions, Statements, and Program Flow Section VThe Standard ANSI C Library with C99 Additions Math Library: math.h Variable Arguments: stdarg.h Standard I/O Library: stdio.h General Utilities: stdlib.h Section VIExtended Integer Types Section VIIExpanded Character Support Section VIIIC99 Numeric Computational Enhancements Section IXDifferences Between C and C++ Top Index C Primer Plus, Fourth EditionBy Stephen Prata Table of Contents Copyright Copyright © 2002 by Sams Publishing All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Library of Congress Catalog Card Number: 2001089225 Printed in the United States of America First Printing: September 2001 03 02 01 00 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Sams Publishing cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Apple is a registered trademark of Apple Computer, Inc Borland C++ is a registered trademark of Borland International, Inc CodeWarrior is a registered trademark of Metrowerks, Inc Cray is a registered trademark of Cray Computer, Inc IBM and PC are registered trademarks and PC DOS is a trademark of the International Business Machines Company Macintosh is a registered trademark of Macintosh Laboratory, Inc., licensed by Apple Computer, Inc Microsoft and MS-DOS are registered trademarks of C Primer Plus, Fourth EditionBy Stephen Prata Table of Contents [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] UCNs (universal character names) 2nd uint_fast16_t type uint_fast32_t type uint_fast64_t type uint_fast8_t type UINT_FASTN_MAX constant uint_least16_t type uint_least32_t type uint_least64_t type uint_least8_t type UINT_LEASTN_MAX constant uint16_t type uint32_t type uint64_t type uint8_t type UINTMAX_MAX constant uintmax_t strtoumax(const char * restrict nptr, char ** restrict endptr, int base) function uintmax_t type uintmax_t wcstoumax(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base) function UINTN_MAX constant UINTPTR_MAX constant uintptr_t type unary operator 2nd unary operator (-) unary operator (-,) unary operator (~) bitwise logical operator 2nd unary operators 2nd 3rd & (ampersand) finding addresses 2nd 3rd 4th * ++ unbalanced binary search trees unbuffered input buffered input, comparing underflows floating-point numbers 2nd underscore (_) variables, naming unechoed input unequal (!=) relational operator ungetc( ) function uninitialized pointers dereferencing 2nd union operators 2nd unions 2nd 3rd - [edit,s/b hyphen and rt angle bracket] (indirect membership operator) (dot operator) 2nd as a structure as an integer C and C++, comparing 2nd initializing variables defining United States Postal Service Web site universal character names (UCNs) 2nd UNIX Unix < [edit, lft angle bracket] (redirection operator) 2nd 3rd 4th [edit, 2 rt angle brackets] operator [edit, rt angle bracket] (redirection operator) 2nd 3rd | (pipe) operator UNIX buffering functions C compilers cc command cc compiler) 2nd compiling on 2nd 3rd Unix Ctrl+D keyboard shortcut 2nd echo eof.c program 2nd UNIX editing on 2nd functions compiling 2nd Unix input redirecting 2nd 3rd 4th 5th 6th ioctl( ) function UNIX make command Unix output redirecting 2nd 3rd 4th 5th 6th redirection combined 2nd 3rd redirection comments 2nd 3rd UNIX programs running Unix I/O functions UNIX Primer Plus, Third Edition [edit, italics] unsigned char types 2nd unsigned int bit fields 2nd unsigned int types unsigned int values printf( ) function unsigned integers keywords unsigned keyword 2nd 3rd unsigned long long strtoull(const char * restrict npt, char ** restrict ept, int base) function unsigned long long types unsigned long strtoul(const char * restrict npt, char ** restrict ept, int base) function unsigned short types unsigned types print2.c program, code 2nd printing 2nd 3rd updating text files 2nd use qc program code 2nd useheader.c program code 2nd usehotel.c control module code 2nd user interfaces buffered input 2nd 3rd 4th character input 2nd 3rd 4th 5th creating 2nd menus browsing 2nd character and numeric input, mixing 2nd 3rd 4th 5th get choice( ) function 2nd 3rd implementing 2nd tasks 2nd numeric input 2nd 3rd 4th 5th utilities ANSI C library;stdlib.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th library;string.h header file 2nd 3rd 4th 5th 6th 7th library;tgmath.h header file 2nd library;time.h header file 2nd 3rd 4th 5th 6th 7th library;wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th library;wctype.h header file 2nd 3rd 4th 5th 6th extended multibyte wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th general utilities library 2nd atexit( ) function 2nd 3rd 4th atexit( ) function, byebye.c program code 2nd exit( ) function 2nd 3rd 4th qsort( ) function 2nd 3rd 4th 5th 6th qsort( ) function, defining mycomp( ) function 2nd 3rd qsort( ) function, qsorter.c program code 2nd wide character wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th wide character classification wctype.h header file 2nd 3rd 4th 5th 6th wide character mapping wctype.h header file 2nd 3rd 4th 5th 6th wide-character string 2nd 3rd 4th Top C Primer Plus, Fourth EditionBy Stephen Prata Table of Contents [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] VA ARGS variadic macro 2nd 3rd va copy( ) macro va end( ) macro va_arg( ) macro va_start( ) macro validating input 2nd 3rd 4th 5th 6th 7th 8th 9th 10th checking.c program 2nd numbers 2nd streams 2nd value long ftell(FILE *) function value variables 2nd value-assigning operators = assignment operator 2nd 3rd value-finding (dereferencing) operation pointers values argv (argument values) 2nd arrays assigning 2nd bit fields expressions 2nd true or false 2nd 3rd 4th fathm ft.c programs printing 2nd floating-point printing showfpt.c program, code 2nd subnormal from functions returning; 2nd 3rd 4th 5th 6th functions return types 2nd int type print1.c program, code 2nd printing lvalues data objects modifiable lvalue rvalues of arrays valid of bits checking 2nd of indexes changing of variables program states, examining 2nd pointer (integers) 2nd pointers integers 2nd printing 2nd return printf( ) function 2nd 3rd scanf( ) function 2nd strcmp( ) function 2nd 3rd 4th 5th returning rvalues unsigned int printf( ) function variables assigning varargs.c program code 2nd vararr2d.c program code 2nd 3rd variable arguments macros 2nd stdarg.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th variable-length arrays dynamic memory allocation 2nd 3rd variable-length arrays (VLAs) variable-length arrays [See VLAs] variables 2nd , (comma) 2nd actual arguments addresses 2nd altering in calling functions 2nd 3rd 4th 5th arguments stdarg.h header file 2nd 3rd stdarg.h header file, varargs.c program code 2nd arrays comparing declarations automatic 2nd 3rd 4th 5th 6th blocks without {} 2nd forc99.c program, code 2nd automatic storage duration 2nd 3rd 4th 5th 6th 7th 8th block scope 2nd blocks hiding outer definitions Bool type Boolean char types declaring 2nd comma sepatated lists const keyword count declaring 2nd 3rd 4th 5th 6th 7th advantages 2nd data types definiing statements external 2nd 3rd 4th declaring 2nd defining 2nd defining declarations global.c program code 2nd initializing 2nd naming 2nd referencing declarations external linkage 2nd external variables declarations header files fathm ft.c program file scope 2nd flags floating-point declaring formal arguments formal parameters function prototype scope 2nd function scope global hiding.c program 2nd hiding.c program, code 2nd identifiers index int type declaring 2nd defining initializing 2nd internal linkage 2nd linkage 2nd 3rd external 2nd internal 2nd no 2nd local names 2nd naming 2nd _ (underscore) case sensitivity reserved identifiers no linkage 2nd num 2nd number pointers 2nd 3rd 4th & (address operator) * (asterisk) 2nd * (indirection operator) 2nd 3rd 4th communicating between functions 2nd 3rd 4th 5th constants declaring 2nd 3rd operations performed with or on variables 2nd 3rd pt ops.c program code 2nd private names qualifying comments keywords properties 2nd 3rd recursion register 2nd restrict keyword return values assigning scope 2nd 3rd 4th 5th scopes 2nd 3rd 4th 5th 6th 7th single-values static block scope 2nd 3rd 4th external linkage 2nd 3rd 4th internal linkage 2nd random number functions 2nd 3rd 4th 5th 6th 7th 8th random number functions, automated re [See ding]2nd [See ding] random number functions, rand0( ) function, code 2nd random number functions, rand0.c function file program, code 2nd random number functions, rand1( ) function, code 2nd random number functions, srand1( ) function, code 2nd 3rd 4th static storage duration 2nd storage clas [See s] storage classes 2nd 3rd 4th 5th 6th automatic 2nd 3rd 4th 5th 6th automatic storage duration 2nd 3rd 4th 5th 6th 7th 8th automatic, blocks without {} 2nd automatic, initializing 2nd external linkage 2nd external variables 2nd 3rd external variables, declaring 2nd external variables, defining 2nd external variables, defining declarations external variables, global.c program code 2nd external variables, initializing 2nd external variables, naming 2nd external variables, referencing declarations forc99.c program code 2nd internal linkage 2nd linkage 2nd no linkage 2nd register 2nd scope 2nd 3rd 4th static storage duration 2nd static, block scope 2nd 3rd 4th static, external linkage 2nd 3rd 4th static, internal linkage 2nd storage duration 2nd storage duration 2nd 3rd structure structures defining 2nd 3rd 4th initializers (designated) 2nd initializing 2nd initializing with storage class duration swapping in calling functions 2nd 3rd 4th 5th true and false unions defining values 2nd assigning program states, examining 2nd volatile keyword variadic functions variable arguments stdarg.h header file 2nd 3rd stdarg.h header file, varargs.c program code 2nd variadic macros 2nd 3rd É (ellipsis) 2nd É(ellipsis) VA ARGS 2nd 3rd variadic.c program code 2nd variadic.c program code 2nd variations strncmp( ) function 2nd varwid.c program code 2nd viewpoints black box functions 2nd views binary 2nd 3rd text 2nd 3rd VLAs (variable-length arrays) 2nd 3rd 4th 5th 6th 7th dynamic memory allocation sizes vararr2d.c program code 2nd 3rd VMS programs running void (*f)(int) macros 2nd void (*signal(int sig, void (*func)(int)))(int) function void (main( ) function) void *bsearch(const void *key,const void *base, size_t nmem, size_t size, int (*comp)(const void *, function void *calloc(size_t nmem, size_t size) function void *malloc(size_t size) function void *memchr(const void *s, int c, size_t n) function void *memcpy(void * restrict s1, const void * restrict s2, size_t n) function void *memmove(void *s1, const void *s2, size_t n) function void *memset(void *s, int v, size_t n) function void *realloc(void *ptr, size_t size) function void _Exit(int status) function void abort(void) function void assert(int exprs) macro void clearerr(FILE *) function void exit(int status) function void feclearexcept(int excepts) function void fegetenv(fenv_t *envp) function void fegetexceptflag(fexcept_t *flagp, int excepts) function void ferai function [See xcept(int excepts)] void fesetenv(const fenv_t *envp) function void fesetexceptflag(const fexcept_t *flagp,int excepts) function void feupdateenv(const fenv_t *envp) function void free(void *ptr) function void functions void longjmp(jmp_buf env, int val) function void perror(const char *) function void qsort(void *base, size_t nmem, size_t size, int (*comp) (const void *, const void *)) function void rewind(FILE *) function void setbuf(FILE * restrict, char * restrict) function void srand(unsigned int function [See d)] void statement void type functions void va_copy(va_list dest, va_list src) macro void va_end(va_list ap) macro void va_start(va_list ap, parmN) macro volatile keyword 2nd 3rd volatile type qualifier 2nd 3rd vowels.c program code 2nd 3rd Top C Primer Plus, Fourth EditionBy Stephen Prata Table of Contents [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] w [edit,enclose in double quotes] mode string w+ [edit,enclose in double quotes] mode string w+b [edit,enclose in double quotes] mode string warnings error messages wb [edit,enclose in double quotes] mode string wb+ [edit,enclose in double quotes] mode string wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th macros defined 2nd types defined 2nd WCHAR_MAX constant WCHAR_MAX macro WCHAR_MIN constant WCHAR_MIN macro wchar_t type 2nd 3rd wctrans_t type wctype.h header file 2nd 3rd 4th 5th 6th macros 2nd types 2nd wctype_t type Web sites gcc compiler reference sources 2nd United States Postal Service WEOF constant expression WEOF macro wheat.c program code 2nd when.c program code listing 2nd while keyword while keywordÓ _ XE Ókeywords whileÓ while loop single-character I/O values processing while loops 2nd (entry-condition loops) ;shoes2.c program, code 2nd { } (curly braces) compound statements (blocks) 2nd conditional loops 2nd entry.c program, code 2nd relational expressions 2nd Bool type boolean.c program, code 2nd cmpflt.c program, code 2nd t and f.c program, code 2nd trouble.c program, code 2nd 3rd 4th truth.c program, code 2nd values, true and false 2nd 3rd 4th relational operators 2nd precedence 2nd structure summing.c program 2nd 3rd reading loop 2nd summing.c program, code 2nd 3rd sweetie1.c program, code 2nd switch statements syntax points terminating 2nd 3rd when.c program, code 2nd while statement 2nd while statements 2nd while1.c program, code 2nd while2.c program, code 2nd while statement 2nd 3rd 4th 5th 6th abbreviating accessing menus entry-condition loops keywords while loops conditional loops 2nd syntax points terminating 2nd 3rd when.c program, code 2nd while1.c program, code 2nd while2.c program, code 2nd while statements 2nd while1.c program code 2nd while2.c program code 2nd whitespace test to detect text breaking into sequences whitespace characters scanf( ) function 2nd whitespaces non-whitespaces test to detect scanf( ) function wide character classification utilities wctype.h header file 2nd 3rd 4th 5th 6th wide character mapping utilities wctype.h header file 2nd 3rd 4th 5th 6th wide character support C and C++, comparing 2nd wide character utilities wchar.h header file 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th wide characters 2nd 3rd 4th 5th 6th extensible wide-character classification functions 2nd null wide wide-character transformation functions 2nd wide-character classification functions 2nd 3rd wide-character I/O functions 2nd 3rd wide-character multibyte conversion functions 2nd 3rd 4th 5th 6th 7th wide-character string utilities 2nd 3rd 4th wide-character transformation functions 2nd width.c program code 2nd widths exact width types 2nd 3rd 4th fastest minimum width types 2nd 3rd 4th 5th greatest width integer functions 2nd maximum width types 2nd 3rd minimum width types 2nd 3rd 4th 5th Windows IDEs (Integrated Development Environments) targets IDEs (Integrated Development Environments) 2nd Windows compilers functions compiling 2nd WINT_MAX constant WINT_MIN constant wint_t type 2nd word-count programs 2nd 3rd wordcnt.c program, code 2nd wordcnt.c program code 2nd words 2nd storing in binary search trees writing binary data to files 2nd C source code 2nd constants with int types programs 2nd text files Top C Primer Plus, Fourth EditionBy Stephen Prata Table of Contents [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [Z] z modifier printf( ) function Zeno zeno.c program code 2nd zippo1.c program 2nd code 2nd zippo2.c program code 2nd 3rd Top ... Section VIExtended Integer Types Section VIIExpanded Character Support Section VIIIC99 Numeric Computational Enhancements Section IXDifferences Between C and C+ + Top Index C Primer Plus, Fourth EditionBy Stephen Prata... Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16... Programming Exercises Chapter 9 Functions Reviewing Functions ANSI C Function Prototyping Recursion All C Functions Are Created Equal Compiling Programs with Two or More Source Code Files

Ngày đăng: 25/03/2019, 16:33

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN