C How To Program 9Th Global Edition Deitel Paul Full Chapter PDF
C How To Program 9Th Global Edition Deitel Paul Full Chapter PDF
C How To Program 9Th Global Edition Deitel Paul Full Chapter PDF
Deitel Paul
Visit to download the full and correct content document:
https://ebookmass.com/product/c-how-to-program-9th-global-edition-deitel-paul/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://ebookmass.com/product/c-how-to-program-9th-edition-
deitel-paul/
https://ebookmass.com/product/c-how-to-program-with-case-studies-
in-applications-and-systems-programming-global-edition-paul-
deitel/
https://ebookmass.com/product/c-how-to-program-an-objects-
natural-approach-11e-11th-edition-paul-deitel/
https://ebookmass.com/product/java-how-to-program-early-objects-
eleventh-edition-deitel/
(eTextbook PDF) for Java How to Program, Early Objects
11th Edition by Paul J. Deitel
https://ebookmass.com/product/etextbook-pdf-for-java-how-to-
program-early-objects-11th-edition-by-paul-j-deitel/
https://ebookmass.com/product/c20-for-programmers-deitel-
developer-series-3rd-edition-paul-deitel/
https://ebookmass.com/product/il-linguaggio-c-fondamenti-e-
tecniche-di-programmazione-9th-edition-paul-j-deitel/
https://ebookmass.com/product/c-how-to-program-8th-edition-ebook-
pdf/
https://ebookmass.com/product/como-programar-en-c-9th-edition-
harvey-deitel/
GLOBAL
EDITION
C HOW TO PROGRAM
NINTH EDITION
The rights of Paul Deitel and Harvey Deitel to be identified as the authors of this work, have been asserted by them in accordance with the Copyright,
Designs and Patents Act 1988.
Authorized adaptation from the United States edition, entitled C How to Program, 9th Edition, ISBN 978-0-13-739839-3 by Paul Deitel and Harvey Deitel
published by Pearson Education © 2022.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic,
mechanical, photocopying, recording or otherwise, without either the prior written permission of the publisher or a license permitting restricted copying in
the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS.
All trademarks used herein are the property of their respective owners. The use of any trademark in this text does not vest in the author or publisher any
trademark ownership rights in such trademarks, nor does the use of such trademarks imply any affiliation with or endorsement of this book by such owners.
For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights and Permissions
department, please visit www.pearsoned.com/permissions/.
This eBook is a standalone product and may or may not include all assets that were part of the print version. It also does not provide access
to other Pearson digital products like MyLab and Mastering. The publisher reserves the right to remove any material in this eBook at any
time.
1 22
Trademarks
Apple, Xcode, Swift, Objective-C, iOS and macOS are trademarks or registered
trademarks of Apple, Inc.
Java is a registered trademark of Oracle and/or its affiliates.
Linux is a registered trademark of Linus Torvalds.
Microsoft and/or its respective suppliers make no representations about the suit-
ability of the information contained in the documents and related graphics published
as part of the services for any purpose. All such documents and related graphics are
provided “as is” without warranty of any kind. Microsoft and/or its respective sup-
pliers hereby disclaim all warranties and conditions with regard to this information,
including all warranties and conditions of merchantability, whether express, implied
or statutory, fitness for a particular purpose, title and non-infringement. In no event
shall Microsoft and/or its respective suppliers be liable for any special, indirect or con-
sequential damages or any damages whatsoever resulting from loss of use, data or
profits, whether in an action of contract, negligence or other tortious action, arising
out of or in connection with the use or performance of information available from
the services.
The documents and related graphics contained herein could include technical inac-
curacies or typographical errors. Changes are periodically added to the information
herein. Microsoft and/or its respective suppliers may make improvements and/or
changes in the product(s) and/or the program(s) described herein at any time. Partial
screen shots may be viewed in full within the software version specified.
Contents
Appendices E–H are PDF documents posted online at the book’s Companion
Website (located at https://www.pearsonglobaleditions.com).
Preface 17
6 Contents
Contents 7
5 Functions 231
5.1 Introduction 232
5.2 Modularizing Programs in C 232
5.3 Math Library Functions 234
5.4 Functions 235
5.5 Function Definitions 236
5.5.1 square Function 236
5.5.2 maximum Function 239
5.6 Function Prototypes: A Deeper Look 240
5.7 Function-Call Stack and Stack Frames 243
5.8 Headers 247
5.9 Passing Arguments by Value and by Reference 249
5.10 Random-Number Generation 249
5.11 Game Simulation Case Study: Rock, Paper, Scissors 254
5.12 Storage Classes 260
5.13 Scope Rules 262
5.14 Recursion 265
5.15 Example Using Recursion: Fibonacci Series 269
5.16 Recursion vs. Iteration 272
5.17 Secure C Programming—Secure Random-Number Generation 275
Random-Number Simulation Case Study: The Tortoise and the Hare 294
6 Arrays 297
6.1 Introduction 298
6.2 Arrays 298
6.3 Defining Arrays 300
6.4 Array Examples 300
DEIT8393_09_GE_Final.book Page 8 Tuesday, April 12, 2022 3:20 PM
8 Contents
7 Pointers 363
7.1 Introduction 364
7.2 Pointer Variable Definitions and Initialization 365
7.3 Pointer Operators 366
7.4 Passing Arguments to Functions by Reference 369
7.5 Using the const Qualifier with Pointers 373
7.5.1 Converting a String to Uppercase Using a Non-Constant
Pointer to Non-Constant Data 374
F02_DEIT8393_09_GE_TOC_final.fm Page 9 Wednesday, April 27, 2022 10:06 AM
Contents 9
10 Contents
Contents 11
12 Contents
Contents 13
14 Contents
14 Preprocessor 735
14.1 Introduction 736
14.2 #include Preprocessor Directive 737
14.3 #define Preprocessor Directive: Symbolic Constants 737
14.4 #define Preprocessor Directive: Macros 738
14.4.1 Macro with One Argument 739
14.4.2 Macro with Two Arguments 740
14.4.3 Macro Continuation Character 740
14.4.4 #undef Preprocessor Directive 740
14.4.5 Standard-Library Macros 740
14.4.6 Do Not Place Expressions with Side Effects in Macros 741
14.5 Conditional Compilation 741
14.5.1 #if…#endif Preprocessor Directive 741
14.5.2 Commenting Out Blocks of Code with #if…#endif 742
14.5.3 Conditionally Compiling Debug Code 742
14.6 #error and #pragma Preprocessor Directives 743
14.7 # and ## Operators 744
14.8 Line Numbers 744
14.9 Predefined Symbolic Constants 745
14.10 Assertions 745
14.11 Secure C Programming 746
Contents 15
C Multithreading/Multicore and
Other C18/C11/C99 Topics 777
C.1 Introduction 778
C.2 Headers Added in C99 779
C.3 Designated Initializers and Compound Literals 779
C.4 Type bool 781
C.5 Complex Numbers 782
C.6 Macros with Variable-Length Argument Lists 784
C.7 Other C99 Features 784
C.7.1 Compiler Minimum Resource Limits 784
C.7.2 The restrict Keyword 784
C.7.3 Reliable Integer Division 785
C.7.4 Flexible Array Members 785
C.7.5 Type-Generic Math 786
C.7.6 Inline Functions 786
C.7.7 __func__ Predefined Identifier 786
C.7.8 va_copy Macro 787
C.8 C11/C18 Features 787
C.8.1 C11/C18 Headers 787
C.8.2 quick_exit Function 787
C.8.3 Unicode® Support 787
C.8.4 _Noreturn Function Specifier 788
C.8.5 Type-Generic Expressions 788
C.8.6 Annex L: Analyzability and Undefined Behavior 788
C.8.7 Memory Alignment Control 789
C.8.8 Static Assertions 789
C.8.9 Floating-Point Types 789
C.9 Case Study: Performance with Multithreading and Multicore Systems 790
C.9.1 Example: Sequential Execution of Two
Compute-Intensive Tasks 793
C.9.2 Example: Multithreaded Execution of Two
Compute-Intensive Tasks 795
C.9.3 Other Multithreading Features 799
DEIT8393_09_GE_Final.book Page 16 Tuesday, April 12, 2022 3:20 PM
16 Contents
Index 805
Online Appendices
E Number Systems
Preface
An Innovative C Programming Textbook for the 2020s
Good programmers write code that humans can understand.1
—Martin Fowler
I think that it's extraordinarily important that we in computer science keep fun in
computing.2
—Alan Perlis
1. Martin Fowler (with contributions by Kent Beck). Refactoring: Improving the Design of Existing
Code. Addison-Wesley, 1999. p. 15.
2. Alan Perlis, Quoted in the book dedication of The Structure and Interpretation of Computer Pro-
grams, 2/e by Hal Abelson, Gerald Jay Sussman and Julie Sussman. McGraw-Hill. 1996.
3. Tiobe Index for November 2020. Accessed November 9, 2020. https://www.tiobe.com/
tiobe-index/.
F03_DEIT8393_09_GE_PREF_final.fm Page 18 Tuesday, April 19, 2022 12:20 PM
18 Preface
We’ll say lots more about these important trends. The Internet of Things (IoT) is
already connecting tens of billions of computerized devices of every imaginable type.
These generate enormous volumes of data (one form of “big data”) at rapidly increas-
ing speeds and quantities. And most computing will eventually be performed online
in “the Cloud”—that is, by using computing services accessible over the Internet.
For the novice, the book’s early chapters establish a solid foundation in program-
ming fundamentals. The mid-range to high-end chapters and the 20+ case studies ease
novices into the world of professional software-development challenges and practices.
Given the extraordinary performance demands that today’s applications place on
computer hardware, software and the Internet, professionals often choose C to build
the most performance-intensive portions of these applications. Throughout the book,
we emphasize performance issues to help you prepare for industry.
The book’s modular architecture (see the chart on the inside front cover) makes
it appropriate for several audiences:
• Introductory and intermediate college programming courses in Computer
Science, Computer Engineering, Information Systems, Information Technolo-
gy, Software Engineering and related disciplines.
• Science, technology, engineering and math (STEM) college courses with a
programming component.
• Professional industry training courses.
• Experienced professionals learning C to prepare for upcoming software-
development projects.
We’ve enjoyed writing nine editions of this book over the last 29 years. We hope you’ll
find C How to Program, 9/e informative, challenging and entertaining as you prepare to
develop leading-edge, high-performance applications and systems in your career.
20 Preface
ments’ enhanced emphasis on security. See the “Computing and Data Science
Curricula” section later in this Preface for a list of the key curricula documents.
• Consistent with our richer treatment of security, we’ve added case studies on
secret-key and public-key cryptography. The latter includes a detailed walk-
through of the enormously popular RSA algorithm’s steps, providing hints to
help you build a working, simple, small-scale implementation.
• We’ve enhanced existing case studies and added new ones focusing on AI and
data science, including simulations with random-number generation, survey
data analysis, natural language processing (NLP) and artificial intelligence
(machine-learning with simple linear regression). Data science is emphasized
in the latest ACM/IEEE computing curricula documents.
• We’ve added exercises in which students use the Internet to research ethics
and privacy issues in computing.
• We tuned our mutltithreading and multicore performance case study. We
PERF also show a performance icon in the margin whenever we discuss a perfor-
mance-related issue in the text.
• We integrated the previous edition’s hundreds of software-development tips
ERR directly into the text for a smoother reading experience. We call out common
SE errors and good software engineering practices with new margin icons.
• We upgraded our appendix on additional sorting algorithms and analysis of
algorithms with Big O to full-chapter status (Chapter 13).
• C programmers often subsequently learn one or more C-based object-oriented
languages. We added an appendix that presents a friendly intro to object-
oriented programming concepts and terminology. C is a procedural program-
ming language, so this appendix will help students appreciate differences in
thinking between C developers and the folks who program in languages like
C++, Java, C#, Objective-C, Swift and other object-oriented languages. We do
lots of things like this in the book to prepare students for industry.
• Several case studies now have you use free open-source libraries and tools.
• We added a case study that performs visualization with gnuplot.
• We removed the previous edition’s introduction to C++ programming to
make room for the hundreds of integrated self-check exercises and our new
applications programming and systems programming case studies.
• This new edition is published in a larger font size and page size for enhanced
readability.
the book’s case studies are located. Some are in-chapter examples and some are end-of-
chapter exercises. Some are fully coded. For others, you’ll develop the solution.
Chapters 1–5 are traditional introductory C programming topics. Chapters 6–11
are intermediate topics forming the high end of Computer Science 1 and related
courses. Chapters 12–15 are advanced topics for late CS1 or early CS2 courses. Here’s
a list of the topical, challenging and often entertaining hands-on case studies.
22 Preface
4. We point out the few cases in which a compiler does not support a particular feature.
F03_DEIT8393_09_GE_PREF_final.fm Page 23 Tuesday, April 19, 2022 12:20 PM
24 Preface
Chapter 8, Characters and Strings, introduces the C standard library’s string, character
and memory-block processing functions. You’ll use these powerful capabilities in
Chapter 11, File Processing, as you work through a natural language processing
(NLP) case study. You’ll see that strings are intimately related to pointers and arrays.
Chapter 11, File Processing, introduces files for long-term data retention, even when
the computer is powered off. Such data is said to be “persistent.” The chapter explains
how plain-text files and binary files are created, updated and processed. We consider
both sequential-access and random-access file processing. In one of our case-study
exercises, you’ll read data from a comma-separated value (CSV) file. CSV is one of the
most popular file formats in the data-science community. This chapter presents our
next case study—Building a Random-Access Transaction-Processing System. We
use random-access files to simulate the kind of high-speed direct-access capabilities
that industrial-strength database-management systems have. This chapter also presents
our first artificial-intelligence/data-science case study, which uses Natural Language
Processing (NLP) techniques to begin investigating the controversial question, “Who
really wrote the works of William Shakespeare?” A second artificial-intelligence/data-
science case study—Machine Learning with the GNU Scientific Library—investi-
gates Anscombe’s Quartet using simple linear regression.5 This is a collection of four
dramatically different datasets that have identical or nearly identical basic descriptive
statistics. It offers a valuable insight for students and developers learning some data-
science basics in this computer-science textbook. The case study then asks you to run
a simple linear regression on 126 years of New York City average January temperature
data to determine if there is a cooling or warming trend.
Our recursion (Chapter 5), arrays (Chapter 6), searching (Chapter 6), data structures
(Chapter 12), sorting (Chapter 13) and Big O (Chapter 13) coverage provides nice
content for a C data structures course.
Chapter 15, Other Topics, covers additional C topics, including multithreading sup-
port (available in GNU gcc, but not Xcode or Visual C++), variable-length argument
lists, command-line arguments, compiling multiple-source-file programs, extern dec-
larations for global variables in other files, function prototypes, restricting scope with
static, makefiles, program termination with exit and atexit, suffixes for integer and
floating-point literals, signal handling, dynamic memory-allocation functions calloc
and realloc and unconditional branching with goto. This chapter presents our final
case study—Performance with Multithreading and Multicore Systems. This case
study demonstrates how to create multithreaded programs that will run faster (and
often much faster) on today’s multicore computer architectures. This is a nice capstone
F03_DEIT8393_09_GE_PREF_final.fm Page 26 Tuesday, April 19, 2022 12:20 PM
26 Preface
case study for a book about C, for which writing high-performance programs is para-
mount.
Appendices
Appendix A, Operator Precedence Chart, lists C’s operators in highest-to-lowest
precedence order.
Appendix B, ASCII Character Set, shows characters and their corresponding
numeric codes.
Appendix C, Multithreading/Multicore and Other C18/C11/C99 Topics, covers
designated initializers, compound literals, type bool, complex numbers, additions to
the preprocessor, the restrict keyword, reliable integer division, flexible array mem-
bers, relaxed constraints on aggregate initialization, type generic math, inline func-
tions, return without expression, __func__ predefined identifier, va_copy macro,
C11 headers, _Generic keyword (type generic expressions), quick_exit function,
Unicode® support, _noreturn function specifier, type-generic expressions, Annex L:
Analyzability and Undefined Behavior, memory-alignment control, static assertions,
floating-point types and the timespec_get function.
Appendix D, Intro to Object-Oriented Programming Concepts, presents a friendly
overview of object-oriented programming terminology and concepts. After learning
C, you’ll likely also learn one or more C-based object-oriented languages—such as
C++, Java, C#, Objective-C or Swift—and use them side-by-side with C.
Online Appendices
Appendix E, Number Systems, introduces the binary, octal, decimal and hexadeci-
mal number systems.
Appendices F–H, Using the Visual Studio Debugger, Using the GNU gdb Debug-
ger and Using the Xcode Debugger, demonstrate how to use our three preferred
compilers’ basic debugging capabilities to locate and correct execution-time problems
in your programs.
Key Features
C Programming Fundamentals
In our rich coverage of C fundamentals:
• We emphasize problem-solving and algorithm development.
• To help students prepare to work in industry, we use the terminology from
the latest C standard documents in preference to general programming terms.
• We avoid heavy math, leaving it to upper-level courses. Optional mathemat-
ical exercises are included for science and engineering courses.
F03_DEIT8393_09_GE_PREF_final.fm Page 27 Tuesday, April 19, 2022 12:20 PM
Key Features 27
28 Preface
9. Robert Fano, quoted in Dream Machine: J.C.R. Licklider and the Revolution That Made Com-
puting Personal by Mitchell Waldrop. Penguin Putnam, 2002. p. 232.
10. “MIT Computer Science and Artificial Intelligence Laboratory.” Accessed November 9, 2020.
https://en.wikipedia.org/wiki/MIT_Computer_Science_and_Artificial_Intelli-
gence_Laboratory.
11. “What is open source?” Accessed November 14, 2020. https://opensource.com/resourc-
es/what-open-source.
F03_DEIT8393_09_GE_PREF_final.fm Page 29 Tuesday, April 19, 2022 12:20 PM
Key Features 29
Visualizations
We include high-level visualizations produced with the gnuplot open-source visual-
ization package to reinforce your understanding of the concepts:
• We use visualizations as a pedagogic tool. For instance, one example makes the
law of large numbers “come alive” in a dice-rolling simulation (see Chapter
10—Raylib Game Programming Case Studies later in this Preface). As this
program performs increasing numbers of die rolls, you’ll see each of the six fac-
es’ (1, 2, 3, 4, 5, 6) percentage of the total rolls gradually approach 16.667%
(1/6th), and the lengths of the bars representing the percentages equalize.
• You should experiment with the code to implement your own visualizations.
Data Experiences
In the book’s examples, exercises and projects—especially in the file-processing chap-
ter—you’ll work with real-world data such as Shakespeare’s play Romeo and Juliet.
You’ll download and analyze text from Project Gutenberg—a great source of free
downloadable texts for analysis. The site contains nearly 63,000 e-books in various
formats, including plain-text files—these are out of copyright in the United States.
You’ll also work with real-world temperature data. In particular, you’ll analyze 126
years of New York City average January temperature data and determine whether
there is a cooling or warming trend. You’ll get this data from National Oceanic and
Atmospheric Administration (NOAA) website noaa.gov.
12. William Gates, quoted in Programmers at Work: Interviews With 19 Programmers Who Shaped
the Computer Industry by Susan Lammers. Microsoft Press, 1986, p. 83.
13. “C.” Accessed January 4, 2021. https://github.com/topics/c.
14. Students will need to become familiar with the variety of open-source licenses for software on
GitHub.
F03_DEIT8393_09_GE_PREF_final.fm Page 30 Tuesday, April 19, 2022 12:20 PM
30 Preface
source community if you like. Fifty million developers use GitHub.15 The
site currently hosts over 100 million repositories for code written in an enor-
mous number of languages16—developers contributed to 44+ million reposi-
tories in 2019 alone.17 GitHub is a crucial element of the professional
software developer’s arsenal with version control tools that help teams of
developers manage public open-source projects and private projects.
• In 2018, Microsoft purchased GitHub for $7.5 billion. If you become a soft-
ware developer, you’ll almost certainly use GitHub regularly. According to Mic-
rosoft’s CEO, Satya Nadella, they bought GitHub to “empower every developer
to build, innovate and solve the world’s most pressing challenges.”18
• We encourage you to study and execute lots of developers’ open-source C
code on GitHub.
Privacy
The ACM/IEEE’s curricula recommendations for Computer Science, Information
Technology and Cybersecurity mention privacy over 200 times. Every programming
student and professional needs to be acutely aware of privacy issues and concerns.
Students research privacy in four exercises in Chapters 1, 3 and 10.
In Chapter 1’s exercises, you’ll start thinking about these issues by researching ever-
stricter privacy laws such as HIPAA (Health Insurance Portability and Accountability
Act) and the California Consumer Privacy Act (CCPA) in the United States and
GDPR (General Data Protection Regulation) for the European Union.
Ethics
The ACM’s curricula recommendations for Computer Science, Information Technol-
ogy and Cybersecurity mention ethics more than 100 times. In several Chapter 1 exer-
cises, you’ll focus on ethics issues via Internet research. You’ll investigate privacy and
ethical issues surrounding intelligent assistants, such as IBM Watson, Amazon Alexa,
Apple Siri, Google Assistant and Microsoft Cortana. For example, a judge ordered
Amazon to turn over Alexa recordings for use in a criminal case.19
Performance
Programmers prefer C (and C++) for performance-intensive operating systems, real-
time systems, embedded systems, game systems and communications systems, so we
focus on performance issues. We use timing operations in our multithreading exam-
15. “GitHub.” Accessed November 14, 2020. https://github.com/.
16. “GitHub is how people build software.” Accessed November 14, 2020. https://github.com/
about.
17. “The State of the Octoverse.” Accessed November 14, 2020. https://octoverse.github.com.
18. “Microsoft to acquire GitHub for $7.5 billion.” Accessed November 14, 2020. https://
news.microsoft.com/2018/06/04/microsoft-to-acquire-github-for-7-5-billion/.
19. “Judge orders Amazon to turn over Echo recordings in double murder case.” Accessed Novem-
ber 14, 2020. https://techcrunch.com/2018/11/14/amazon-echo-recordings-judge-
murder-case/.
F03_DEIT8393_09_GE_PREF_final.fm Page 31 Tuesday, April 19, 2022 12:20 PM
Key Features 31
32 Preface
You’ll use the free tier of the Webot robotics simulator to explore their dozens of
simulated robots. You’ll execute various full-color 3D robotics simulations written
in C and study the provided code. Webots is a self-contained development environ-
ment that provides a C code editor and compiler. You’ll use these tools to program
your own simulations using Webot’s robots.
Webots provides lots of fully coded C programs. A great way for you to learn C
is to study existing programs, modify them to work a bit differently and observe the
results. Many prominent robotics companies use Webots simulators to prototype
new products.
F03_DEIT8393_09_GE_PREF_final.fm Page 33 Tuesday, April 19, 2022 12:20 PM
34 Preface
• The Spot-On game tests your reflexes by requiring you to click moving spots
before they disappear. With each new game level the spots move faster, mak-
ing them harder to click.
• The Cannon game challenges you to repeatedly aim and fire a cannon to
destroy nine moving targets before a time limit expires. A moving blocker
makes the game more difficult.
• The Law of Large Numbers dynamic animated visualization repeatedly rolls
a six-sided die and creates an animated bar chart. Visualizations give you a
powerful way to understand data that goes beyond simply looking at raw data.
This case study exercise allows students to see the “law of large numbers” at
work. When repeatedly rolling a die, we expect each die face to appear approx-
imately 1/6th (16.667%) of the time. For small numbers of rolls (e.g., 60 or
600), you’ll see that the frequencies typically are not evenly distributed. As
you simulate larger numbers of die rolls (e.g., 60,000), you’ll see the die fre-
quencies become more balanced. When you simulate significant numbers of
die rolls (e.g., 60,000,000), the bars will appear to be the same size.
The games and simulation use various raylib capabilities, including shapes, colors,
sounds, animation, collision detection and user-input events (such as mouse clicks).
After studying our code, you’ll use the raylib graphics, animation and sound fea-
tures you learn to enhance your implementation of Chapter 5’s Tortoise and the
Hare Race. You’ll incorporate a traditional horse race’s sounds, and multiple tortoise
and hare images to create a fun, animated multimedia “extravaganza.” Then, you’ll
use a raylib to enhance this chapter’s high-performance card-shuffling-and-dealing
simulation to display card images. Finally, you can select from 10 additional raylib
game-programming and simulation exercises. Get creative—have some fun design-
ing and building your own games, too!
the paid (NPL) tool Grammarly22 to help tune the writing and ensure the text’s read-
ability for a wide audience. Instructors who use the “flipped classroom” format prefer
textbooks that students can understand on their own.
Some people believe that the works of William Shakespeare actually might have
been written by Christopher Marlowe or Sir Francis Bacon among others.23,24 In the
NLP case study exercise, you’ll use array-, string- and file-processing techniques to per-
form simple similarity detection on Shakespeare’s Romeo and Juliet and Marlowe’s
Edward the Second to determine how alike they are. You may be surprised by the results.
Chapter 11—Web Services and the Cloud: Getting a Weather Report Using
libcurl and the OpenWeatherMap Web Services; Introducing Mashups
More and more computing today is done “in the cloud,” using software and data dis-
tributed across the Internet worldwide. The apps we use daily are heavily dependent
on various cloud-based services. A service that provides access to itself over the Inter-
net is known as a web service. In this case study exercise, you’ll work through a com-
pletely coded application that uses the open-source C library libcurl to invoke an
22. Grammarly has free and paid versions (https://www.grammarly.com). They provide free plug-
ins you can use in several popular web browsers.
23. “Did Shakespeare Really Write His Own Plays?” Accessed November 13, 2020. https://
www.history.com/news/did-shakespeare-really-write-his-own-plays.
24. “Shakespeare authorship question.” Accessed November 13, 2020. https://en.wikipedia.org/
wiki/Shakespeare_authorship_question.
25. “Anscombe’s quartet.” Accessed November 13, 2020. https://en.wikipedia.org/wiki/
Anscombe%27s_quartet.
F03_DEIT8393_09_GE_PREF_final.fm Page 36 Tuesday, April 19, 2022 12:20 PM
36 Preface
OpenWeatherMap (free tier) web service that returns the current weather for a spec-
ified city. The web service returns results in JSON (JavaScript Object Notation) for-
mat, which we process using the open-source cJSON library.
This exercise opens a world of possibilities. You can explore nearly 24,000 web
services listed in the ProgrammableWeb26 web services directory. Many are free or
provide free tiers that you can use to create fun and interesting mashups that combine
complementary web services.
Secure C Programming 37
Secure C Programming
The people responsible for the ACM/IEEE curricula guidelines emphasize the impor-
tance of security—it’s mentioned 395 times in the Computer Science Curricula
document and 235 times in the Information Technology Curricula document. In
2017, the ACM/IEEE published its Cybersecurity Curricula, which focuses on secu-
rity courses and security throughout the other computing curricula. That document
mentions security 865 times.
Chapters 2–12 and 14 each end with a Secure C Programming section. These are
designed to raise awareness among novice programming students of security issues that
could cause breaches. These sections present some key issues and techniques and pro-
vide links and references so you can continue learning. Our goal is to encourage you to
start thinking about security issues, even if this is your first programming course.
Experience has shown that it’s challenging to build industrial-strength systems
that stand up to attacks. Today, via the Internet, such attacks can be instantaneous
and global in scope. Software vulnerabilities often come from simple programming
issues. Building security into software from the start of the development cycle can sig-
nificantly reduce vulnerabilities.
The CERT Division of Carnegie Mellon’s Software Engineering Institute
https://www.sei.cmu.edu/about/divisions/cert/index.cfm
was created to analyze and respond promptly to attacks. They publish and promote
secure coding standards to help C programmers and others implement industrial-
strength systems that avoid the programming practices that leave systems vulnerable
to attacks. Their standards evolve as new security issues arise.
We explain how to upgrade your code (as appropriate for an introductory book)
to conform to the latest secure C coding recommendations. If you’re building C sys-
tems in industry, consider reading the SEI CERT C Coding Standard rules at
https://wiki.sei.cmu.edu/confluence/display/c
Also, consider reading Secure Coding in C and C++, 2/e by Robert Seacord
(Addison-Wesley Professional, 2013). Mr. Seacord, a technical reviewer for an earlier
edition of this book, provided specific recommendations on each of our Secure C
Programming sections. At the time, he was the Secure Coding Manager at CERT and
an adjunct professor at Carnegie Mellon’s School of Computer Science. He is now a
Technical Director at NCC Group (an IT Security company).
Our Secure C Programming sections discuss many important topics, including:
• Testing for Arithmetic Overflows
• The More Secure Functions in the C Standard’s Annex K
• The Importance of Checking the Status Information Returned by Standard-
Library Functions
• Range Checking
• Secure Random-Number Generation
F03_DEIT8393_09_GE_PREF_final.fm Page 38 Tuesday, April 19, 2022 12:20 PM
38 Preface
Computing Curricula
• According to “CC2020: A Vision on Computing Curricula,”31 the curricu-
lum “needs to be reviewed and updated to include the new and emerging areas
of computing such as cybersecurity and data science.”32 (See “Data Science
Overlaps with Computer Science” below and this Preface’s earlier “Secure C
Programming” section).
• Data science includes key topics (besides statistics and general-purpose pro-
gramming) such as machine learning, deep learning, natural language process-
ing, speech synthesis and recognition, and others that are classic artificial
intelligence (AI) topics—and hence CS topics as well. We cover machine
learning and natural language processing in the case studies.
https://cc2020.nsparc.ms-
27. “Computing Curricula 2020.” Accessed November 22, 2020.
state.edu/wp-content/uploads/2020/11/Computing-Curricula-Report.pdf.
28. ACM/IEEE (Assoc. Comput. Mach./Inst. Electr. Electron. Eng.). 2013. Computer Science Curric-
ula 2013: Curriculum Guidelines for Undergraduate Degree Programs in Computer Science (New
York: ACM), http://ai.stanford.edu/users/sahami/CS2013/final-draft/CS2013-final-
report.pdf.
29. Information Technology Curricula 2017, http://www.acm.org/binaries/content/assets/
education/it2017.pdf.
30. Cybersecurity Curricula 2017, https://cybered.hosting.acm.org/wp-content/uploads/
2018/02/newcover_csec2017.pdf.
31. A. Clear, A. Parrish, G. van der Veer and M. Zhang, “CC2020: A Vision on Computing Curric-
ula,” https://dl.acm.org/citation.cfm?id=3017690.
32. http://delivery.acm.org/10.1145/3020000/3017690/p647-clear.pdf.
F03_DEIT8393_09_GE_PREF_final.fm Page 39 Tuesday, April 19, 2022 12:20 PM
33. This section is intended primarily for data science instructors. Given that the emerging 2020
Computing Curricula for computer science and related disciplines is likely to include some key
data science topics, this section includes important information for computer science instruc-
tors as well.
34. “Curriculum Guidelines for Undergraduate Programs in Data Science,” http://www.annual-
reviews.org/doi/full/10.1146/annurev-statistics-060116-053930.
35. “Appendix—Detailed Courses for a Proposed Data Science Major,” http://www.annualre-
views.org/doi/suppl/10.1146/annurev-statistics-060116-053930/suppl_file/
st04_de_veaux_supmat.pdf.
F03_DEIT8393_09_GE_PREF_final.fm Page 40 Tuesday, April 19, 2022 12:20 PM
40 Preface
Docker
We introduce Docker—a tool for packaging software into containers that bundle every-
thing required to execute that software conveniently, reproducibly and portably across
platforms. Some software packages you’ll use require complicated setup and configura-
tion. For many of these, you can download free preexisting Docker containers that help
you avoid complex installation issues. You can simply execute software locally on your
desktop or notebook computers, making Docker a great way to help you get started with
new technologies quickly, conveniently and economically. For your convenience, we
show how to install and execute a Docker container that’s pre-configured with the GNU
Compiler Collection (GCC), which includes the gcc compiler. This can run in Docker
on Windows, macOS and Linux. It’s particularly useful for people using Visual C++,
which can compile C code but is not 100% compliant with the latest C standard.
Docker also helps with reproducibility. Custom Docker containers can be con-
figured with every piece of software and every library you use. This would enable oth-
ers to recreate the environment you used, then reproduce your work, and will help
you reproduce your own results. Reproducibility is especially important in the sci-
ences and medicine—for example, when researchers want to prove and extend the
work in published articles.
Flipped Classrooms
Many instructors use “flipped classrooms.”36,37 Students learn the content on their
own before coming to class, and class time is used for tasks such as hands-on coding,
working in groups and discussions. Our book and supplements also are appropriate
for flipped classrooms:
• We use Grammarly to control the book’s reading level to help ensure it’s
appropriate for students learning on their own.
• In parallel with reading the text, students should execute the 147 live-code C
examples and do the 350+ integrated Self Check exercises, which are imme-
diately followed by their answers. These encourage active participation by
36. https://en.wikipedia.org/wiki/Flipped_classroom.
37. https://www.edsurge.com/news/2018-05-24-a-case-for-flipping-learning-without-
videos.
F03_DEIT8393_09_GE_PREF_final.fm Page 41 Tuesday, April 19, 2022 12:20 PM
Teaching Approach 41
the student. They learn the content in small pieces using a “read-a-little, do-
a-little, test-a-little” approach—appropriate for a flipped classroom’s active,
self-paced, hands-on learning. Students are encouraged to modify the code
and see the effects of their changes.
• We provide 445 exercises and projects, which students can work on at home
and/or in class. Many of the exercises are at an elementary or intermediate
level that students should be able to do independently. And many are appro-
priate for group projects on which students can collaborate in class.
• Section-by-section detailed chapter summaries with bolded key terms help
students quickly review the material.
• In the book’s extensive index, the defining occurrences of key terms are high-
lighted with a bold page number, making it easy for students to find the intro-
ductions to the topics they’re studying. This facilitates the outside-the-
classroom learning experience of the flipped classroom.
A key aspect of flipped classrooms is getting your questions answered when you’re
working on your own. See the “Getting Your Questions Answered” section later in
this Preface for details. And you can always reach us at [email protected].
Teaching Approach
This title contains a rich collection of examples, exercises, projects and case studies
drawn from many fields. Students solve interesting, real-world problems working
with real-world data. The book concentrates on the principles of good software
engineering and stresses program clarity.
Syntax Shading
For readability, we syntax shade all the code. Our syntax-coloring conventions are as
follows:
comments appear in gray
keywords appear in bold blue
constants and literal values appear in bold light blue
all other code appears in black
42 Preface
Examples
The book’s 147 live-code examples contain thousands of lines of proven code.
Programming Wisdom
We integrate into the text discussions programming wisdom and mistakes we’ve
accumulated from our combined nine decades of programming and teaching experi-
ence, and from the scores of academics and industry professionals who have reviewed
the nine editions of this book over the past 29 years, including:
• Good programming practices and preferred C idioms that help you produce
clearer, more understandable and more maintainable programs.
ERR • Common programming errors to reduce the likelihood that you’ll make them.
• Error-prevention tips with suggestions for exposing bugs and removing them
from your programs. Many of these tips describe techniques for preventing
bugs from getting into your programs in the first place.
PERF • Performance tips highlighting opportunities to make your programs run
faster or minimize the amount of memory they occupy.
SE • Software engineering observations highlighting architectural and design
issues for proper software construction, especially for larger systems.
SEC • Security best practices that will help you strengthen your programs against
attacks.
Section-By-Section Chapter Summaries
To help students quickly review the material, each chapter ends with a detailed bullet-
list summary with bolded key terms and, for most, bold page references to their defin-
ing occurrences.
C Documentation 43
gives Visual C++ users a true C compiler option, since Visual C++ is not 100% com-
pliant with the latest C standard.
Windows Subsystem for Linux
The Windows Subsystem for Linux (WSL) enables Windows users to install Linux
and run it inside Windows. We provide a link to Microsoft’s step-by-step instructions
for setting up WSL and installing a Linux distribution. This provides yet another
option for Windows users to access the GNU gcc compiler.
C Documentation
You’ll find the following documentation helpful as you work through the book:
• The GNU C Standard Library Reference Manual:
https://www.gnu.org/software/libc/manual/pdf/libc.pdf
• C Language Reference at cppreference.com
https://en.cppreference.com/w/c
• C Standard Library Headers at cppreference.com
https://en.cppreference.com/w/c/header
• Microsoft’s C Language Reference:
https://docs.microsoft.com/en-us/cpp/c-language/c-language-
reference
44 Preface
(Kansan-laulu)
(1) Tästä näkyy, että Suomalaisen orjalla oli sama oikeus kun
hebrealaisenkin. Hän sai kuuden palvelus-vuoden perästä lähteä
pois seitsemäntenä, vapaana lunastamata 2 Mos. 21:2.
KULTAANSA SUREWA
(Kansan-laulu)
Itkettää ja surettaa ja
huoleks' tahtoo tulla,
Kuin on muilla kultasensa
eikä ole mulla.
Kultani on kaukana ja
kaukana se kukkuu;
Yksin täytyy maata mennä,
yksin täytyy nukkuu.
(Kansan-laulu) (1)
Suosio on soma
Onnen siemen oma,
Josta kasvu kaunis ilmestyy;
Sillä suloisella
Levon laitumella
Kaikki meille hyvin menestyy.
Sydän siivollinen,
Rinta riemullinen
Sulattaavat mielen suosioon;
Mutta viha, vaino,
Kateuskin kaino
Jouduttavat järjen turmioon.
Karhu kontiolla
Woipi vielä olla
Luonto kauhiampi lausuttaa,
Kuin on kulkevalla
Wainon vallan alla,
Joka pahan sisun paisuttaa.
Tunnoton ja tuima,
Päästä hullu, huima
Siis on suotta nurja sovintoon;
Sillä kukin kurja,
Hirmun henki, hurja
Waipunut on itse vahinkoon.
J. Juteini
LEIWOSELLE
Kiilto-mato kukkasissa
Loisti hiljasuudesaan
Yli kedon, tienohissa,
Tietämätön loistostaan.
E. Lönnrot
E. Lönnrot
Tutkittaissa tuntoansa,
Taikka muuta menoansa,
Miehen tavat tunnetaan,
Joilla arvo ansaitaan.
J. Juteini
TALON-POJAN LAULU
Talon-poika, taitava
Elon etsinnöissä,
Aina olen alkava
Päivät pellon töissä;
Näissä voiman näytän,
Kaikki hyvin käytän,
Aina työni täytän,
Urhollisena.
Ei omalla pellolla
Aura paljo paina,
Mies on itse ilolla
Ahkera siell’ aina.
Waimo, kuva valon,
Ompi turva talon,
Äiti joukon jalon
Toimellisena.
Tämä sääty suuri on,
Suuri Suomen kansa,
Eikä ole osaton
Perhe pellollansa;
Itse täytän aitan,
Leivän paksun laitan,
Toisellekkin taitan
Riemullisena.
Tavara on tallella
Tämän säädyn tiellä;
Siis on syytä suojella
Wapautta vielä;
Sydämellä, suulla
Esivaltaa kuulla,
Hyvää muista luulla,
Alinomati.
J. Juteini
NUOREN-MIEHEN LAULU
(Ruotsinkielisen johdosta.)