Tải bản đầy đủ (.pdf) (957 trang)

Sams Teach Yourself C in 21 Days potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.53 MB, 957 trang )

800 East 96th St., Indianapolis, Indiana, 46240 USA
Bradley L. Jones and
Peter Aitken
C
in
21
Days
Teach Yourself
SIXTH EDITION
00 448201x-FM 2/5/04 1:15 PM Page i
Sams Teach Yourself C in 21 Days,
Sixth Edition
Copyright © 2003 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, photo-
copying, recording, or otherwise, without written permission from the pub-
lisher. 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. Neither is any liability assumed for damages resulting from the use
of the information contained herein.
International Standard Book Number: 0-672-32448-2
Library of Congress Catalog Number: 2002106120
Printed in the United States of America
First Printing: September 2002
060504 6543
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 servicemark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as
possible, but no warranty or fitness is implied. The information provided is on
an “as is” basis. The authors and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris-
ing from the information contained in this book or from the use of the CD or
programs accompanying it.
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in quan-
tity for bulk purchases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419

For sales outside of the U.S., please contact
International Sales
1-317-428-3341

ASSOCIATE PUBLISHER
Michael Stephens
MANAGING EDITOR
Charlotte Clapp
PROJECT EDITORS
Elizabeth Finney
Katelyn Cozatt
INDEXER
Bruce Clingaman
Lisa Wilson
PROOFREADER
Abby VanHuss

TECHNICAL EDITOR
Mark Cashman
TEAM COORDINATOR
Lynne Williams
INTERIOR DESIGN
Gary Adair
COVER DESIGN
Aren Howell
LAYOUT TECHNICIAN
Juli Cook
00 448201x-FM 2/5/04 1:15 PM Page ii
Contents at a Glance
Introduction 1
Week 1 At a Glance 5
Day 1 Getting Started with C 7
Type and Run 1 25
2 The Components of a C Program 29
3 Storing Information: Variables and Constants 41
4 Statements, Expressions, and Operators 59
Type and Run 2 93
5 Functions: The Basics 97
6 Controlling Your Program’s Order of Execution 123
7 Fundamentals of Reading and Writing Information 147
Week 1 In Review 167
Week 2 At a Glance 173
8 Using Numeric Arrays 175
9 Understanding Pointers 195
Type and Run 3 219
10 Working with Characters and Strings 223
11 Implementing Structures, Unions, and TypeDefs 249

12 Understanding Variable Scope 285
Type and Run 4 305
13 Advanced Program Control 309
14 Working with the Screen, Printer, and Keyboard 337
Week 2 In Review 377
Week 3 At a Glance 385
15 Pointers: Beyond the Basics 387
16 Using Disk Files 439
Type and Run 5 475
00 448201x-FM 8/13/02 11:16 AM Page iii
17 Manipulating Strings 481
18 Getting More from Functions 515
19 Exploring the C Function Library 533
Type and Run 6 561
20 Working with Memory 565
21 Advanced Compiler Use 593
Week 3 In Review 619
Bonus Week at a Glance 627
Bonus Day 1 Objected-Oriented Programming Languages 629
Bonus Day 2 The C++ Programming Language 649
Bonus Day 3 Working with C++ Classes and Objects 665
Bonus Day 4 The Java Programming Language 703
Bonus Day 5 Programming Java Applets 723
Bonus Day 6 Building a Java Applet 743
Bonus Day 7 The C# Programming Languages 765
Bonus Week in Review 781
Appendixes
A ASCII Character Chart 783
B C/C++ Reserved Words 789
C Working with Binary and Hexadecimal Numbers 793

D Portability Issues 797
E Common C Functions 823
F Answers 829
G Getting Started with Dev-C++ 881
Index 893
00 448201x-FM 8/13/02 11:16 AM Page iv
Table of Contents
Introduction 1
This Book’s Special Features 1
Making a Better Book 3
The CD-Rom and the Book’s Code 4
Conventions Used in This Book 4
W
EEK 1ATAGLANCE 5
Where You’re Going 5
D
AY 1 Getting Started with C 7
A Brief History of the C Language 7
Why Use C? 8
Preparing to Program 9
The Program Development Cycle 10
Creating the Source Code 10
Compiling the Source Code 12
Linking to Create an Executable File 13
Completing the Development Cycle 13
Your First C Program 16
Entering and Compiling hello.c 16
Summary 20
Q&A 20
Workshop 21

Quiz 21
Exercises 22
T
YPE & RUN 1 Printing Your Listings 25
The First Type & Run 26
D
AY 2 The Components of a C Program 29
A Short C Program 29
The Program’s Components 31
The
main() Function (Lines 8 Through 23) 31
The
#include Directive (Line 2) 31
The Variable Definition (Line 4) 32
The Function Prototype (Line 6) 32
Program Statements (Lines 11, 12, 15, 16, 19, 20, 22, and 28) 32
00 448201x-FM 8/13/02 11:16 AM Page v
The Function Definition (Lines 26 Through 29) 33
Program Comments (Lines 1, 10, 14, 18, and 25) 33
Using Braces (Lines 9, 23, 27, and 29) 34
Running the Program 35
A Note on Accuracy 35
A Review of the Parts of a Program 36
Summary 38
Q&A 38
Workshop 39
Quiz 39
Exercises 39
D
AY 3 Storing Information: Variables and Constants 41

Understanding Your Computer’s Memory 42
Storing Information with Variables 43
Variable Names 43
Numeric Variable Types 44
Variable Declarations 48
The
typedef Keyword 49
Initializing Variables 49
Constants 50
Literal Constants 51
Symbolic Constants 52
Summary 56
Q&A 56
Workshop 57
Quiz 57
Exercises 58
D
AY 4 The Pieces of a C Program: Statements, Expressions,
and Operators 59
Statements 60
The Impact of Whitespace on Statements 60
Creating a Null Statements 61
Working with Compound Statements 61
Understanding Expressions 62
Simple Expressions 62
Complex Expressions 62
Operators 64
The Assignment Operator 64
The Mathematical Operators 64
Operator Precedence and Parentheses 69

Order of Sub-expression Evaluation 71
The Relational Operators 71
vi Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page vi
The if Statement 73
The
else Clause 76
Evaluating Relational Expressions 78
The Precedence of Relational Operators 80
The Logical Operators 81
More on True/False Values 83
The Precedence of Operators 83
Compound Assignment Operators 85
The Conditional Operator 86
The Comma Operator 86
Operator Precedence Revisited 87
Summary 88
Q&A 89
Workshop 89
Quiz 90
Exercises 90
T
YPE & RUN 2 Find the Number 93
D
AY 5 Packaging Code in Functions 97
What Is a Function? 98
A Function Defined 98
A Function Illustrated 98
How a Function Works 100
Functions and Structured Programming 102

The Advantages of Structured Programming 102
Planning a Structured Program 103
The Top-Down Approach 104
Writing a Function 105
The Function Header 105
The Function Body 108
The Function Prototype 113
Passing Arguments to a Function 114
Calling Functions 115
Recursion 116
Where the Functions Belong 118
Working with Inline Functions 119
Summary 119
Q&A 120
Workshop 121
Quiz 121
Exercises 121
Contents vii
00 448201x-FM 8/13/02 11:16 AM Page vii
DAY 6 Basic Program Control 123
Arrays: The Basics 124
Controlling Program Execution 125
The
for Statement 125
Nesting
for Statements 131
The
while Statement 133
Nesting
while Statements 136

The
do while Loop 138
Nested Loops 142
Summary 143
Q&A 144
Workshop 144
Quiz 144
Exercises 145
D
AY 7 Fundamentals of Reading and Writing Information 147
Displaying Information On-Screen 148
The
printf() Function 148
The
printf() Format Strings 148
Displaying Messages with
puts() 156
Inputting Numeric Data with
scanf() 157
Using Trigraph Sequences 162
Summary 163
Q&A 164
Workshop 164
Quiz 164
Exercises 165
W
EEK 1 IN REVIEW 167
W
EEK 2 ATAGLANCE 173
Where You’re Going 173

D
AY 8 Using Numeric Arrays 175
What Is an Array? 175
Using Single-Dimensional Arrays 176
Using Multidimensional Arrays 180
Naming and Declaring Arrays 181
Initializing Arrays 184
Initializing Multidimensional Arrays 184
Maximum Array Size 188
Summary 191
viii Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page viii
Q&A 191
Workshop 192
Quiz 192
Exercises 193
D
AY 9 Understanding Pointers 195
What Is a Pointer? 196
Your Computer’s Memory 196
Creating a Pointer 196
Pointers and Simple Variables 197
Declaring Pointers 197
Initializing Pointers 198
Using Pointers 198
Pointers and Variable Types 201
Pointers and Arrays 202
The Array Name as a Pointer 202
Array Element Storage 203
Pointer Arithmetic 206

Pointer Cautions 210
Array Subscript Notation and Pointers 211
Passing Arrays to Functions 211
Summary 216
Q&A 217
Workshop 217
Quiz 218
Exercises 218
T
YPE & RUN 3 Pausing for a Second or Two 219
D
AY 10 Working with Characters and Strings 223
The
char Data Type 224
Using Character Variables 224
Using Strings 227
Arrays of Characters 228
Initializing Character Arrays 228
Strings and Pointers 229
Strings Without Arrays 229
Allocating String Space at Compilation 230
The
malloc() Function 230
Using the
malloc() Function 231
Displaying Strings and Characters 235
The
puts() Function 236
The
printf() Function 237

Contents ix
00 448201x-FM 8/13/02 11:16 AM Page ix
Reading Strings from the Keyboard 237
Inputting Strings Using the
gets() Function 237
Inputting Strings Using the
scanf() Function 241
Summary 243
Q&A 244
Workshop 245
Quiz 245
Exercises 246
D
AY 11 Implementing Structures, Unions, and TypeDefs 249
Working with Simple Structures 250
Defining and Declaring Structures 250
Accessing Members of a Structure 251
Using Structures That are More Complex 254
Including Structures Within Other Structures 254
Structures That Contain Arrays 257
Arrays of Structures 260
Initializing Structures 263
Structures and Pointers 266
Including Pointers as Structure Members 266
Creating Pointers to Structures 268
Working with Pointers and Arrays of Structures 270
Passing Structures as Arguments to Functions 273
Understanding Unions 275
Defining, Declaring, and Initializing Unions 275
Accessing Union Members 276

Creating Synonyms for Structures with
typedef 281
Summary 282
Q&A 282
Workshop 283
Quiz 283
Exercises 283
D
AY 12 Understanding Variable Scope 285
What Is Scope? 286
A Demonstration of Scope 286
Why Is Scope Important? 288
Creating External Variables 288
External Variable Scope 289
When to Use External Variables 289
The
extern Keyword 289
x Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page x
Creating Local Variables 291
Static Versus Automatic Variables 291
The Scope of Function Parameters 294
External Static Variables 294
Register Variables 295
Local Variables and the
main() Function 296
Which Storage Class Should You Use? 296
Local Variables and Blocks 297
Summary 299
Q&A 299

Workshop 300
Quiz 300
Exercises 301
T
YPE & RUN 4 Secret Messages 305
D
AY 13 Advanced Program Control 309
Ending Loops Early 310
The
break Statement 310
The
continue Statement 312
The
goto Statement 314
Infinite Loops 316
The
switch Statement 321
Exiting the Program 329
The
exit() Function 330
Executing Operating System Commands
in a Program 330
Summary 333
Q&A 333
Workshop 334
Quiz 334
Exercises 335
D
AY 14 Working with the Screen, Printer, and Keyboard 337
Streams and C 337

What Exactly Is Program Input/Output? 338
What Is a Stream? 339
Text Versus Binary Streams 339
Predefined Streams 339
Using C’s Stream Functions 340
An Example 341
Contents xi
00 448201x-FM 8/13/02 11:16 AM Page xi
Accepting Keyboard Input 342
Character Input 342
Working with Formatted Input 350
Controlling Output to the Screen 358
Character Output with
putchar(), putc(), and fputc() 358
Using
puts() and fputs() for String Output 360
Using
printf() and fprintf() for Formatted Output 361
Redirecting Input and Output 368
Redirecting Input 369
When to Use
fprintf() 370
Using
stderr 370
Summary 372
Q&A 373
Workshop 374
Quiz 374
Exercises 375
W

EEK 2 IN REVIEW 377
W
EEK 3 ATAGLANCE 385
Where You’re Going 385
D
AY 15 Pointers: Beyond the Basics 387
Declaring Pointers to Pointers 387
Pointers and Multidimensional Arrays 389
Working with Arrays of Pointers 397
Strings and Pointers: A Review 398
Declaring an Array of Pointers to Type
char 398
Pulling Things Together With an Example 401
Working with Pointers to Functions 406
Declaring a Pointer to a Function 407
Initializing and Using a Pointer to a Function 407
Bonus Section: Understanding Linked Lists 416
Basics of Linked Lists 416
Working with Linked Lists 417
A Simple Linked List Demonstration 423
Implementing a Linked List 426
Summary 434
Q&A 434
Workshop 435
Quiz 435
Exercises 437
xii Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page xii
DAY 16 Using Disk Files 439
Relating Streams to Disk Files 439

Understanding the Types of Disk Files 440
Using Filenames 440
Opening a File 441
Writing and Reading File Data 445
Formatted File Input and Output 445
Character Input and Output 450
Direct File Input and Output 452
File Buffering: Closing and Flushing Files 455
Understanding Sequential Versus Random File Access 457
The
ftell() and rewind() Functions 458
The
fseek() Function 460
Detecting the End of a File 463
File Management Functions 465
Deleting a File 465
Renaming a File 466
Copying a File 467
Using Temporary Files 470
Summary 471
Q&A 472
Workshop 473
Quiz 473
Exercises 473
T
YPE & RUN 5 Counting Characters 475
D
AY 17 Manipulating Strings 481
Determining String Length 481
Copying Strings 483

The
strcpy() Function 483
The
strncpy() Function 485
The
strdup() Function 486
Concatenating Strings 487
Using the
strcat() Function 487
Using the
strncat() Function 489
Comparing Strings 490
Comparing Two Entire Strings 491
Comparing Partial Strings 493
Comparing Two Strings While Ignoring Case 494
Searching Strings 494
The
strchr() Function 495
The
strrchr() Function 496
Contents xiii
00 448201x-FM 8/13/02 11:16 AM Page xiii
The strcspn() Function 496
The
strspn() Function 498
The
strpbrk() Function 499
The
strstr() Function 499
String Conversions 501

Miscellaneous String Functions 502
The
strrev() Function 502
The
strset() and strnset() Functions 502
String-to-Number Conversions 504
Converting Strings to Integers 504
Converting Strings to Longs 504
Converting Strings to Long Longs 505
Converting Strings to Floating Point Numeric Values 505
Character Test Functions 506
ANSI Support for Uppercase and Lowercase 510
Summary 512
Q&A 512
Workshop 512
Quiz 513
Exercises 513
D
AY 18 Getting More from Functions 515
Passing Pointers to Functions 515
Type
void Pointers 520
Using Functions That Have a Variable Number of Arguments 523
Functions That Return a Pointer 526
Summary 528
Q&A 529
Workshop 529
Quiz 529
Exercises 530
D

AY 19 Exploring the C Function Library 533
Mathematical Functions 533
Trigonometric Functions 534
Exponential and Logarithmic Functions 534
Hyperbolic Functions 535
Other Mathematical Functions 535
A Demonstration of the Math Functions 536
Dealing with Time 537
Representing Time 537
The Time Functions 538
Using the Time Functions 541
xiv Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page xiv
Error-Handling 543
The
assert() Macro 544
The
errno.h Header File 546
The
perror() Function 547
Searching and Sorting 548
Searching with
bsearch() 549
Sorting with
qsort() 550
Searching and Sorting: Two Demonstrations 550
Summary 556
Q&A 557
Workshop 557
Quiz 557

Exercises 558
T
YPE & RUN 6 Calculating Mortgage Payments 561
D
AY 20 Working with Memory 565
Type Conversions 565
Automatic Type Conversions 566
Explicit Conversions Using Typecasts 568
Allocating Memory Storage Space 570
Allocating Memory with the
malloc() Function 571
Allocating Memory with the
calloc() Function 574
Allocating More Memory with the
realloc() Function 575
Releasing Memory with the
free() Function 577
Manipulating Memory Blocks 579
Initializing Memory with the
memset() Function 579
Copying Memory with the
memcpy() Function 580
Moving Memory with the
memmove() Function 580
Working with Bits 582
The Shift Operators 582
The Bitwise Logical Operators 584
The Complement Operator 586
Bit Fields in Structures 586
Summary 588

Q&A 588
Workshop 589
Quiz 589
Exercises 590
D
AY 21 Advanced Compiler Use 593
Programming with Multiple Source-Code Files 593
Advantages of Modular Programming 594
Modular Programming Techniques 594
Contents xv
00 448201x-FM 8/13/02 11:16 AM Page xv
Module Components 597
External Variables and Modular Programming 598
Using .obj Files 599
Using the Make Utility 600
The C Preprocessor 601
The
#define Preprocessor Directive 601
Using the
#include Directive 606
Using
#if, #elif, #else, and #endif 607
Using
#if #endif to Help Debug 608
Avoiding Multiple Inclusions of Header Files 609
The
#undef Directive 610
Predefined Macros 611
Using Command-Line Arguments 612
Summary 614

Q&A 615
Workshop 615
Quiz 616
Exercises 616
W
EEK 3 IN REVIEW 619
B
ONUS WEEK ATAGLANCE 627
Where You’re Going 627
B
ONUS DAY 1 Object-Oriented Programming Languages 629
Procedural and Object-Oriented Languages 630
The Object-Oriented Constructs 631
Adapting with Polymorphism 631
Encapsulating It All 634
Pulling from the Past with Inheritance 636
OOP in Action 636
The Relationship of C++ to C 640
C++ Programs 640
The Java Programming Language 641
The Relationship of Java to C and C++ 641
Java’s Platform Independence 642
Packages 643
Java Applets Versus Applications 643
Java’s Class Libraries 643
Saying Hello, World with Java 644
The C# Programming Language 645
Summary 646
Q&A 646
xvi Sams Teach Yourself C in 21 Days

00 448201x-FM 8/13/02 11:16 AM Page xvi
Workshop 646
Quiz 647
Exercises 647
B
ONUS DAY 2 The C++ Programming Language 649
Hello C++ World! 650
Printing in C++ 651
Understanding the C++ Keywords 652
The C++ Data Types 653
Declaring Variables in C++ 653
Doing Operations in C++ 655
Working with Functions in C++ 655
Overloading Functions 655
Creating Default Function Parameter Values 656
Inline Functions 658
Summary 661
Q&A 662
Workshop 662
Quiz 663
Exercises 663
B
ONUS DAY 3 Working with C++ Classes and Objects 665
Working with Complex Data in C++ 666
Using Functions with Structures 667
Using Classes 674
Controlling Access to Data in a Class 675
Setting the Access Type on Class Data 677
Creating Access Member Functions 680
Structures Versus Classes 683

Housekeeping with Classes 684
Starting with Constructors 684
Ending with Destructors 684
Using Constructors and Destructors 684
Function Overloading Revisited 686
Review of the OOP Constructs in C++ 687
Using Classes as Data Members 688
Accessing Classes in Classes 689
Inheriting in C++ 689
Building a Base Class for Inheritance 690
The Protected Access Data Modifier 692
Inheriting from a Base Class 693
Constructors and Destructors Revisited 696
Contents xvii
00 448201x-FM 8/13/02 11:16 AM Page xvii
A Caution on What You’ve Learned About C++ 698
Where to Go to Learn More 699
Summary 699
Q&A 699
Workshop 700
Quiz 700
Exercises 701
B
ONUS DAY 4 Java Language Fundamentals 703
Structure of a Java Program 703
Java Program Essentials 704
Working with Imports 704
Methods 705
Comments 705
Java Keywords 706

Java Identifiers 707
Data Types 708
The Primitive Data Types 708
Constants 710
Declaring and Initializing Variables 710
Variable Scope 710
Storing String Data 711
Input and Output 713
Arrays 715
Operators 716
Flow Control 717
if else 717
while and do while 718
switch 718
for 719
Summary 720
Q&A 720
Workshop 720
Quiz 721
Exercise 721
B
ONUS DAY 5 Working with Java Classes and Methods 723
Defining a Class 723
Specifying the Class Package 725
Creating Class Properties 725
A Simple Demonstration 726
xviii Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page xviii
Class Methods 727
A Method Demonstration 728

Overloading Methods 731
Class Constructors 733
Using Inheritance 736
Summary 740
Q&A 740
Workshop 741
Quiz 741
B
ONUS DAY 6 More Java Techniques 743
Working with Java Exceptions 743
Reading and Writing Files 745
Reading Text Files 745
Writing Text Files 747
Doing Graphics and Windows 749
Creating Windowing Applications 749
Drawing Shapes and Lines 751
Using Buttons and Pop-Up Windows 754
Programming Java Applets 758
Differences Between Applets and Applications 759
Understanding the Structure of an Applet 759
Putting an Applet on a Web Page 760
Using an Applet 761
Summary 763
Q&A 763
Workshop 764
Quiz 764
B
ONUS DAY 7 The C# Programming Language 765
What Is C#? 765
Why C#? 766

C# Is Simple 767
C# Is Modern 767
C# Is Object-Oriented 767
C# Is Powerful and Flexible 768
C# Is a Language of Few Words 768
C# Is Modular 769
C# Will Be Popular 769
C# Versus Other Programming Languages 769
Types of C# Programs 770
Contents xix
00 448201x-FM 8/13/02 11:16 AM Page xix
Creating a C# Program 770
Naming Your Source Files 771
Executing a C# Program 771
Compiling C# Source Code 772
The C# Compiler and the .NET Runtime 773
Your First C# Program 773
Displaying Basic Information 774
C# and the Web 776
Summary 778
Q&A 778
Workshop 779
Quiz 779
Exercises 779
B
ONUS WEEK IN REVIEW 781
A
PPENDIX A ASCII Character Chart 783
A
PPENDIX B C/C++ Reserved Words 789

A
PPENDIX C Working with Binary and Hexadecimal Numbers 793
The Decimal Number System 793
The Binary System 794
The Hexadecimal System 794
A
PPENDIX D Portability Issues 797
The ANSI Standard 797
The ANSI Keywords 798
Case Sensitivity 798
Portable Characters 800
Guaranteeing ANSI Compatibility 800
Avoiding the ANSI Standard 801
Using Portable Numeric Variables 801
Maximum and Minimum Values 803
Classifying Numbers 809
Converting a Character’s Case: A Portability Example 814
Portable Structures and Unions 815
Word Alignment 815
Reading and Writing Structures 816
Using Non-ANSI Features in Portable Programs 817
ANSI Standard Header Files 820
Summary 820
Q&A 820
xx Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page xx
Workshop 821
Quiz 821
Exercises 821
A

PPENDIX E Common C Functions 823
A
PPENDIX F Answers 829
Answers for Day 1 829
Quiz 829
Exercises 830
Answers for Day 2 831
Quiz 831
Exercises 831
Answers for Day 3 832
Quiz 832
Exercises 833
Answers for Day 4 834
Quiz 834
Exercises 835
Answers for Day 5 836
Quiz 836
Exercises 837
Answers for Day 6 840
Quiz 840
Exercises 841
Answers for Day 7 842
Quiz 842
Exercises 842
Answers for Day 8 847
Quiz 847
Exercises 847
Answers for Day 9 851
Quiz 851
Exercises 852

Answers for Day 10 853
Quiz 853
Exercises 855
Answers for Day 11 857
Quiz 857
Exercises 857
Answers for Day 12 858
Quiz 858
Exercises 859
Contents xxi
00 448201x-FM 8/13/02 11:16 AM Page xxi
Answers for Day 13 863
Quiz 863
Exercises 863
Answers for Day 14 864
Quiz 864
Exercises 865
Answers for Day 15 866
Quiz 866
Exercises 867
Answers for Day 16 867
Quiz 867
Exercises 868
Answers for Day 17 868
Quiz 868
Exercises 869
Answers for Day 18 869
Quiz 869
Exercises 870
Answers for Day 19 871

Quiz 871
Exercises 871
Answers for Day 20 872
Quiz 872
Exercises 873
Answers for Day 21 874
Quiz 874
Answers for Day 22 874
Quiz 874
Answers for Day 23 875
Quiz 875
Answers for Day 24 876
Quiz 876
Answers for Day 25 877
Quiz 877
Answers for Day 26 877
Quiz 877
Answers for Day 27 878
Quiz 878
Answers for Day 28 878
Quiz 878
Exercises 879
xxii Sams Teach Yourself C in 21 Days
00 448201x-FM 8/13/02 11:16 AM Page xxii
APPENDIX G Getting Started with Dev-C++ 881
What is Dev-C++ 882
Installing Dev-C++ on Microsoft Windows 882
The Dev-C++ Programs 885
Using Dev-C++ 885
Customizing Dev-C++ for C Programming 885

Entering and Compiling with Dev-C++ 887
Compiling a Dev-C++ Program 890
Running a Program Created with Dev-C++ 891
Summary 892
Index 893
Contents xxiii
00 448201x-FM 8/13/02 11:16 AM Page xxiii
xxiv Sams Teach Yourself C in 21 Days
About the Authors
BRADLEY L. JONES works with internet.com overseeing the EarthWeb software develop-
ment channel. This includes overseeing sites such as Developer.com, CodeGuru.com, and
Gamelan.com. He has directed the development of systems, both small scale and distrib-
uted as well as on a variety of platforms from the Palm OS to mainframe systems. He
has developed systems using such tools as C, C#, C++, XML, SQL Server,
PowerBuilder, Visual Basic, Active Server Pages (ASP), Satellite Forms, and more.
Jones’s other authoring credits include Sams Teach Yourself Advanced C in 21 Days
(Sams Publishing) and Sams Teach Yourself C# in 21 Days (Sams Publishing).
P
ETER AITKEN has been writing about computers and programming for over 10 years,
with some 30 books and hundreds of magazine and trade publication articles to his
credit. His recent book titles include Visual Basic .NET Programming With Peter Aitken,
Office XP Development With VBA, XML the Microsoft Way, Windows Script Host, and
Sams Teach Yourself Visual Basic .NET Internet Programming in 21 Days. For several
years he was a Contributing Editor at Visual Developer magazine where he wrote a
popular Visual Basic column, and he is a regular contributor to Microsoft OfficePro
magazine and the DevX Web site. Peter is the proprietor of PGA Consulting, providing
custom application and Internet development to business, academia, and government
since 1994. You can reach him at

00 448201x-FM 8/13/02 11:16 AM Page xxiv

×