Updated for C11
Write powerful C programs…without becoming a technical expert! This book is the fastest way to get comfortable with C, one incredibly clear and easy step at a time. You’ll learn all the basics: how to organize programs, store and display data, work with variables, operators, I/O, pointers, arrays, functions, and much more. C programming has neverbeen this simple!
Who knew how simple C programming could be?
This is today’s best beginner’s guide to writing C programs–and to learning skills you can use with practically any language. Its simple, practical instructions will help you start creating useful, reliable C code, from games to mobile apps. Plus, it’s fully updated for the new C11 standard and today’s free, open source tools! Here’s a small sample of what you’ll learn:
• Discover free C programming tools for Windows, OS X, or Linux
• Understand the parts of a C program and how they fit together
• Generate output and display it on the screen
• Interact with users and respond to their input
• Make the most of variables by using assignments and expressions
• Control programs by testing data and using logical operators
• Save time and effort by using loops and other techniques
• Build powerful data-entry routines with simple built-in functions
• Manipulate text with strings
• Store information, so it’s easy to access and use
• Manage your data with arrays, pointers, and data structures
• Use functions to make programs easier to write and maintain
• Let C handle all your program’s math for you
• Handle your computer’s memory as efficiently as possible
• Make programs more powerful with preprocessing directives
Author(s): Greg Perry; Dean Miller
Edition: 3rd
Publisher: Pearson Education
Year: 2014
Language: English
Pages: 334
Tags: c programming;cs50 books;cs50;c language;programming;
About This eBook......Page 2
Title Page......Page 3
Copyright Page......Page 4
Contents at a Glance......Page 6
Table of Contents......Page 8
About the Authors......Page 13
Dedication......Page 14
Acknowledgments......Page 15
We Want to Hear from You!......Page 16
Reader Services......Page 17
What Makes This Book Different?......Page 18
This Book’s Design Elements......Page 19
What Do I Do Now?......Page 20
Part I: Jumping Right In......Page 21
What Is a Program?......Page 22
What You Need to Write C Programs......Page 23
The Programming Process......Page 26
Using C......Page 27
A Down-and-Dirty Chunk of Code......Page 29
The main() Function......Page 31
Kinds of Data......Page 32
Wrapping Things Up with Another Example Program......Page 36
Commenting on Your Code......Page 38
Specifying Comments......Page 39
Whitespace......Page 41
A Second Style for Your Comments......Page 42
How to Use printf()......Page 44
Printing Strings......Page 45
Escape Sequences......Page 46
Conversion Characters......Page 48
Putting It All Together with a Code Example......Page 50
Kinds of Variables......Page 52
Naming Variables......Page 53
Defining Variables......Page 54
Storing Data in Variables......Page 55
Understanding the String Terminator......Page 59
The Length of Strings......Page 60
Character Arrays: Lists of Characters......Page 61
Initializing Strings......Page 63
Including Files......Page 66
Placing #include Directives......Page 68
Defining Constants......Page 69
Building a Header File and Program......Page 70
Prompting for scanf()......Page 73
Problems with scanf()......Page 75
Part II: Putting C to Work for You with Operators and Expressions......Page 79
Basic Arithmetic......Page 80
Order of Operators......Page 83
Assignments Everywhere......Page 85
Compound Assignment......Page 88
Watch That Order!......Page 91
Typecasting: Hollywood Could Take Lessons from C......Page 92
Testing Data......Page 94
Using if......Page 96
Otherwise...: Using else......Page 98
Getting Logical......Page 102
Avoiding the Negative......Page 106
The Order of Logical Operators......Page 108
Goodbye if...else; Hello, Conditional......Page 111
The Small-Change Operators: ++ and --......Page 114
Sizing Up the Situation......Page 116
Part III: Fleshing Out Your Programs......Page 118
while We Repeat......Page 119
Using while......Page 120
Using do...while......Page 122
for Repeat’s Sake!......Page 125
Working with for......Page 127
Take a break......Page 132
Let’s continue Working......Page 134
17. Making the case for the switch Statement......Page 137
Making the switch......Page 138
break and switch......Page 140
Efficiency Considerations......Page 141
putchar() and getchar()......Page 147
The Newline Consideration......Page 149
A Little Faster: getch()......Page 151
Character-Testing Functions......Page 153
Is the Case Correct?......Page 154
Case-Changing Functions......Page 156
String Functions......Page 157
Practicing Your Math......Page 161
Doing More Conversions......Page 162
Getting into Trig and Other Really Hard Stuff......Page 163
Getting Random......Page 166
Part IV: Managing Data with Your C Programs......Page 170
Reviewing Arrays......Page 171
Putting Values in Arrays......Page 174
Filling Arrays......Page 177
Finders, Keepers......Page 178
Putting Your House in Order: Sorting......Page 183
Faster Searches......Page 187
Defining Pointer Variables......Page 192
Using the Dereferencing *......Page 194
Array Names Are Pointers......Page 199
Getting Down in the List......Page 200
Characters and Pointers......Page 201
Be Careful with Lengths......Page 202
Arrays of Pointers......Page 204
26. Maximizing Your Computer’s Memory......Page 208
But Why Do I Need the Heap?......Page 209
How Do I Allocate the Heap?......Page 210
Freeing Heap Memory......Page 213
Multiple Allocations......Page 214
Defining a Structure......Page 219
Putting Data in Structure Variables......Page 223
Part V: Files and Functions......Page 227
Disk Files......Page 228
Opening a File......Page 229
Using Sequential Files......Page 230
Opening Random Files......Page 236
Moving Around in a File......Page 237
Form Follows C Functions......Page 242
Local or Global?......Page 245
Passing Arguments......Page 249
Methods of Passing Arguments......Page 250
Returning Values......Page 257
The return Data Type......Page 260
One Last Step: Prototype......Page 261
Wrapping Things Up......Page 262
Appendixes......Page 264
A. The ASCII Table......Page 265
B. The Draw Poker Program......Page 271
Index......Page 279