Beginning Programming with C Errata

Updates and Corrections

Last updated September 28, 2015

Page 2
In the second sentence, the keyword if should be lower case.
Page 10
The first sentence in the section Acquiring an Integrated Development Environment (IDE) should read, "It's completely admirable for you to begin your programming journey . . ."
If you're having difficulties with Code::Blocks on a Macintosh because a compiler isn't present, see my Code::Blocks info page for the Mac.
Page 20
The sidebar mentions the random() function. This function is available in some C language libraries, but not all. The traditional function is rand().
Page 34
The fourth and fifth paragraphs are duplicates. I've no idea where the first one came from. The second one I wrote. The editor changed it to read, "You can also send information to functions and get something back," which apparently didn't make it into the book. Weird.
Page 42
For some reason, I used the " (double quote) character in the second paragraph after Listing 3-8, first sentence. It should read, "When you type the first double quote for printf(), you see the second double quote appear automatically."
Page 55
The second example, printf() doesn't include the colon in the text Goodbye, cruel world. The colon is part of the preceding paragraph, not the output.
Page 57
First paragraph below the heading, second sentence, the word complier appears instead of compiler.
Page 61
The sample output from Exercise 5-1 should use the value 968 not 869.
Page 74
A C variable name cannot contain a dash, as referenced on this page's fourth paragraph. The dash is interpreted as a minus sign.
Page 75
At the top of the page, character value 'a' is placed into char variable c. The code does not use a variable a.
Page 110
The default part of a switch-case structure is optional. The text states that "it must be specified," but this is incorrect.
Page 115
The exit_condition paragraph should state that "the statements continue to repeat until the exit condition is true."
Page 119
In Listing 9-5, the putchar() function at Line 13 has a comma where you should find a single quote. The code should look like this:
putchar('\n');      /* end a line of text */
Page 131
See the solution for Exercise 10-1 for an explanation of why I set the buffer size and size value in the fgets() function differently. (Short answer: They can be the identical.)
Page 152
The entries for floor() and ceil() in Table 11-3 are reversed. The ceil() function rounds up, floor() rounds down.
The first paragraph below Table 11-3 refers to Table 11-2. It should refer to Table 11-3.
Page 156
The constant WAVELENGTH is really the wave's amplitude, or its "height" going left-to-right. The constant PERIOD actually describes the wavelength, which is the depth of the wave, measured on the screen from top to bottom.
Page 194
The fourth US President was James Madison. James Monroe was the fifth US President.
Page 200
The third to last paragraph misspells the scanf() function as sacnf().
Page 201
First sentence: A structure is a type of variable in the C language, it's just not a traditional type like char or int and it's not an individual variable.
Page 204
The statement "You can get away with this trick only once" (at the top of the page) is invalid. Two methods exist to create and fill multiple structures as they're declared. Both of these methods are illustrated on the solution page for Exercise 14-5.
Page 211
Under Step 2, the final Exercise in Chapter 14 is ex1409, not ex1410.
Page 224
Twice on this page the text refers to Listing 16-4. It should be Listing 16-5. Also see my notes for Exercise 16-5.
Page 226
Second paragraph: The variable feet is mistyped as the word float.
Page 228
Listing 16-7 uses the srandom() and random() functions. These functions are available only in some C language libraries. Use the srand() and rand() functions (respectively) instead for greater compatibility. Also see Listing 16-7.
The paragraph after the listing should refer to Listing 16-7 not Listing 16-1.
page 232
Third to last paragraph: A modern byte has only 8 bits, not 255. The total values represented by those 8 bits can be 256, which are the integers from 1 to 255 and then zero.
Page 240
The first sentence under the heading: Both ~ and ! are unary operators that work in a binary fashion.
Page 241
In Table 17-3, last item, the binary NOT operator is !. The table lists the ~ operator instead.
Page 243
Turns out that you can use the >> and << operators in C++ to shift bits in an integer value. I wouldn't have known that, so I appreciate Igor, the C++ programmer who pointed it out.
Page 244
The first figure, "signed char" is incorrect when it states that the bits represent values -129 and -130. Those values are impossible. The real values are -127 and -126, respectively.
Page 256
The third bullet is confusing. My point is this: Use the sizeof operator on a structure variable, not the structure's definition. In Listing 18-3, sizeof is used on the structure itself because no structure variable is declared. When the variable is declared, its size could be larger than the structure's size, specifically when the structure contains one or more char members or a char array. Because all variables are aligned in memory, padding is added between the structure members, which explains the size difference.
Page 258
The squares representing variables in Figure 18-2 are not the size of the variables themselves, and the names are copied from Figure 18-1, which is inaccurate. Click here to view the correct figure.
Page 272
Paragraph starting with ++: The value at the address is written, not read.
Page 273
Fourth paragraph, last sentence: Variable pn should be pa, which is the pointer variable used in Listing 19-4.
Page 283
The second paragraph, in Line 10 the ampersand & obtains the address of float variable price, not the percent sign (%).
Page 285
Fourth paragraph, last sentence: The i-- statement at Line 25 backs up to the newline character, not before it. See my notes for Exercise 19-26.
Page 290
The fgets() function's size option can be set equal to the buffer size, 1024 bytes in Listing 20-2. That's because fgets() stops reading input at one less than the size value specified. So the value 1023 in the code listing, as well as in the paragraph that follows, can be 1024. Also see the listing for Exercise 20-4.
Pages 301 to 304
Listing 20-8 contains a bug at Line 130. The if test to ensure that value r is in range is located at the wrong spot in the code. It should appear after the c++ statement. Refer to the online solution for Exercise 20-12 for a proper listing.
Page 305
The second paragraph refers to Listing 20-3, when it should refer to Listing 20-8.
Page 308
A few trivial booboos on this page: Julius Caesar and Pope Gregory did not develop their namesake calendars; they adopted them. The Gregorian calendar was adopted in 1582. The Julian Day set January 1, 4713 BC as zero, and the Modified Julian Date (MJD) uses November 17, 1858 as zero.
Page 309
The time() function does, in fact, return a value: a time_t value.
Page 310
The line below Listing 21-1 refers to Listing 21-2, but it should read Listing 21-1.
Page 311
In the box about the time() function, the last sentence should refer to unsigned long int. The word "value" appears instead of int.
Page 321
Second paragraph after the code listing: The \0 (null character) is neither written to nor read from the file. The \0 marks the end of the string, so it isn't put to the file. And the \0 is not used within the file to mark the EOF.
Page 342
Bottom of page: Lines 8 through 14 create the file, not Lines 9 through 15. And at the top of Page 343, the first paragraph refers to Line 16, not Lines 17 and 18.
Page 344
Below Listing 23-6, Line 7 contains the unlink() function, not Line 9.
Page 358
Step 5, the putchar() function displays a character on the screen, not a random character. According to the code, the character is defined within the loop. The word "random" is also used on page 359 below Step 13. Again, the character isn't random.
Page 360
The code in Listing 25-2 doesn't contain any bugs. The paragraph afterwards implies that it does, but the code's purpose is simply to watch variables in the debugger.