C in a Nutshell

Errata for C in a Nutshell

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
ePub
Page 16
2nd paragraph from the bottom

delcared -> declared

Note from the Author or Editor:
Thanks!

Anonymous  Oct 15, 2012 
Printed
Page 23
Table 2-4

The maximum value listed for a four byte unsigned int is shown as: 2,147,483,647. That would be correct for a four byte signed int, but for a four byte unsigned int the value should be: 4,294,967,295.

Anonymous    May 11, 2012
Printed
Page 25
3rd paragraph from the bottom

The reference to Table 2-4 should refer to Table 2-5 instead.

Note from the Author or Editor:
Indeed, the third paragraph from the bottom of page 25 should read: The types listed in Table 2-5 are usually defined as synonyms for existing standard types.

Anonymous    May 11, 2012
Printed
Page 34
4th paragraph

0x.02B3p0 should be 0x.02BCp0

Anonymous    May 11, 2012
Printed
Page 57
line 2

Change "expression" to "assignment"

Anonymous    May 11, 2012
Printed
Page 65
last paragraph

pg 65 (Ch 5, increment and decrement operators), 4th line from the bottom of the page: ++(*p) should be: ++(*p1)

Anonymous  Jan 27, 2011  May 11, 2012
Printed
Page 68
last paragraph, line 5

Change "... if the left operand yields 1; " to "... if the left operand yields a non-zero value; "

Anonymous    May 11, 2012
Printed
Page 75
second to last line before the heading "Other Operators" (last line of the three code example lines)

Add missing right parenthesis before the dot: (*(arrArticle+i)).number

Anonymous    May 11, 2012
Printed
Page 78
Examples after second paragraph

With gcc-4.0.0 (Mac OS X, PowerPC), the expression "sizeof(*int)" gives rise to a parse error ("parse error before 'int'"). Using "sizeof(int*) instead works fine.

Note from the Author or Editor:
In the second line of examples at the top of page 78, change the first expression from "sizeof(*int)" to "sizeof(int*)".

Anonymous    May 11, 2012
Printed
Page 106
The 6th non-blank line of Example 7-7 (the body of function 'swapf')

The last occurrence of 'p2' should be preceded by an asterisk.

Anonymous    May 11, 2012
Printed
Page 109
under the list item "void va_end( va_list, argptr );", line 3

Change "a function pointer" to "an argument pointer"

Anonymous    May 11, 2012
Printed
Page 113
in both code fragments, middle and bottom of page

Change "myarray" to "myArray" in a total of three instances

Anonymous    May 11, 2012
Printed
Page 114
in the for loop after 2nd paragraph

the comparison in the for loop *p < myArray + A_SIZE compares between an integer and a pointer which is not the intended purpose here. It gives warning on gcc 4.1.0 it should be p < myArray + A_SIZE so that for loop ends when we reach past the end of myArray. No warning then as we compare pointer to a pointer.

Note from the Author or Editor:
The reader is correct. The example after the second paragraph on p. 114 should read: for ( long *p = myArray; p < myArray + A_SIZE; ++p ) *p *= 2;

Anonymous  Jun 08, 2008  May 11, 2012
Printed
Page 117
Code snippet, middle of page

if ( sizeof(str1) >= ( strlen( str1 ) + strlen( str2 ) + 1 ) should be: if ( sizeof(str1) >= ( strlen( str1 ) + strlen( str2 ) + 1 ) )

Anonymous    May 11, 2012
Printed
Page 127
bottom/128, top

Omit "(see "Implicit Pointer Conversion" in Chapter 4)" and at the end of the paragraph (page 128, top), add: "(see "Comparative Operators" in Chapter 5)" ^

Anonymous    May 11, 2012
Printed
Page 129
bottom, last line before the example

Change "a constant pointer does not necessarily point to a constant object:" to "a constant pointer is not the same thing as a pointer to a constant object:"

Anonymous    May 11, 2012
Printed
Page 131
bottom, line 1 of the example

Change "int a[200];" to "char a[200];"

Anonymous    May 11, 2012
Printed
Page 140
line 7 (the second one-line code snippet)

Change struct Date { short year, month, day; }; to struct Date { short month, day, year; }; [[to match subsequent initialization on p. 144]].

Anonymous    May 11, 2012
Printed
Page 172
Third bullet point

Please change the third bullet point as follows * Nodes in a binary tree are placed according to this rule: the value of a node is greater than or equal to the values of any descendant in its left branch, and less than or equal to the value of any descendant in its right branch.

Anonymous    May 11, 2012
Printed
Page 181
line 5

Change "Example 12-2" to "Example 12-3"

Anonymous    May 11, 2012
Printed
Page 192
bottom

If possible, insert two "include" directives before the searchFile function begins, as follows: // ------------------------------------------------- #include <stdio.h> #include <string.h> int searchFile( FILE fpIn, const char *keyword )

Anonymous    May 11, 2012
Printed
Page 194
line 16

Change "ARRAY_LEN" to "ARRAY_LEN * sizeof(Record_t)" and move the comment up a line, thus: else //Create the buffer. if ((pArray = malloc( ARRAY_LEN * sizeof(Record_t) )) == NULL ) error_exit( 3, "Insufficient memory.");

Anonymous    May 11, 2012
Printed
Page 194
line 32 (8 lines above the "Formatted Output" heading)

Change if ( i > 0 ) // Write the remaining records. to if ( i > 0 && !ferror(fpOut) ) // Write the remaining records.

Anonymous    May 11, 2012
Printed
Page 205
bottom, second to last text line before example

Change "message.txt" to "messages.txt"

Anonymous    May 11, 2012
Printed
Page 264
top

There are four more functions that actually belong in Table 16-18. They are declared in inttypes.h, so that the table should have another column on the right. Furthermore, the paragraph introducing the table needs a couple more sentences to introduce these functions. These changes may be too extensive for the English version, but they have been made in preparing the German version. Here is how the table and its introduction should look, following on the existing sentence "The functions for char strings are declared in the header stdlib.h, and those for wide strings in wchar.h.": Four new functions introduced in C99, declared in inttypes.h, convert a string into the widest available signed or unsigend integer type, intmax_t or uintmax_t. Table 16-18: Conversion of numeral strings Conversion Functions in stdlib.h Functions in wchar.h Functions in inttypes.h -------------------------------------------------------------------------------------------------------- String to int atoi() String to long atol(), strtol() wcstol() String to unsigned long strtoul() wcstoul() String to long long atoll(), strtoll() wcstoll() String to unsigned long long strtoull() wcstoull() String to intmax_t strtoimax() wcstoimax String to uintmax_t strtoumax() wcstoumax String to float strtof() wcstof() String to double atof(), strtod() wcstod() String to long double strtold() wcstold()

Anonymous    May 11, 2012
Printed
Page 287
Section "carg", line 1 of the Example

Change "real" to "complex", thus: /* Convert a complex number from Cartesian to polar coordinates. */

Anonymous    May 11, 2012
Printed
Page 288
section "casinh", the Synopsis line

Change "cosine" to "sine", thus: Calculates the inverse hyperbolic sine of a number

Anonymous    May 11, 2012
Printed
Page 288
end of page

Omit the last part of the "See Also" list from the last semicolon on: i.e., let the list end with "and tanh()"

Anonymous    May 11, 2012
Printed
Page 290
section "cbrt", last line of the example

Change "sma_km" to "dist_km", thus: printf("Then your planet must be about %.0lf km from the Sun. ", dist_km );

Anonymous    May 11, 2012
Printed
Page 295

Insert a section for the function clog() before section "conj" (if possible). Contents as follows (keeping it short): clog C99 ___________________________________________________________________ Calculates the natural logarithm of a complex number #include <complex.h> double complex clog( double complex z ); float complex clogf( float complex z ); long double complex clogl( long double complex z ); The clog() function returns the logarithm to base e of its complex argument. The imaginary part of the return value is in the interval [-pii, +pii] Example double complex z = clog( -1.0 ); // z = 0.0 + 3.1415926 * I See Also: cexp(), cpow()

Anonymous   
Printed
Page 312
section "feholdexcept", lines 2 and 8 of the example

Change "hypoteneuse" to "hypotenuse" in two instances.

Anonymous    May 11, 2012
Printed
Page 315
top, second to last line of the example for feraiseexcept()

Change "%flags X. " to "flags %X. "

Anonymous    May 11, 2012
Printed
Page 316
section "fesetround"

Add "C99" tag at right in the heading line, thus: fesetround C99 ________________________________________________________

Anonymous    May 11, 2012
Printed
Page 318
section "fflush"

First paragraph, third sentence: Change "If the file is only opened for reading, the function clears the buffer." to "If the file is only opened for reading, the behavior of fflush() is not specified by the standard. Most implementations simply clear the input buffer." Insert a sentence at the beginning of the second paragraph: "The argument passed to fflush() may be a null pointer. In this case, fflush() flushes the output buffers of all the program's open streams.

Anonymous    May 11, 2012
Printed
Page 323
section "fgetws", first text paragraph, line 3

Change "char pointer" to "wchar_t pointer"

Anonymous    May 11, 2012
Printed
Page 334
bottom, last text paragraph, first line

Change "of the input string,tony:x:1002:1002:, and copies" to "of the input string,tony:x:1002:31:, and copies"

Anonymous    May 11, 2012
Printed
Page 337
lines 21 to 33 of the example code.

(Code change because fgets() returns NULL at end-of-file): Change 21 if ( ! fgets(sLine,MAX_LINE,fp )) // Read next line from file. 22 { 23 fprintf(stderr,"Unable to read from %s ",argv [2 ] )); 24 break; 25 } 26 } while ( strstr( sLine, argv[1] ) == NULL ); // Test for argument in sLine. 27 28 /* Dropped out of loop: Found search keyword or EOF */ 29 if ( feof(fp) ) 30 { 31 fprintf( stderr,"Unable to find "%s" in %s ", argv[1], argv[2] ); 32 rewind(fp); 33 } to if ( ! fgets(sLine,MAX_LINE,fp )) // Read next line from file. { break; } } while ( strstr( sLine, argv[1] ) == NULL ); // Test for argument in sLine. /* Dropped out of loop: Found search keyword or EOF */ if ( feof(fp) || ferror(fp) ) { fprintf( stderr,"Unable to find "%s" in %s ", argv[1], argv[2] ); rewind(fp); } In other words, delete line 23 of the example completely, and and insert "|| ferror(fp) " in line 29.

Anonymous    May 11, 2012
Printed
Page 339
lines 2 and 3

Change "under wchar.h in Chapter 15" to "in table 16-2"

Anonymous    May 11, 2012
Printed
Page 341
Second Example Code

In the second example code page 341, printed version We found: char file_name[256} Where it should be the code: char file_name[256] , closing the square bracket.

Note from the Author or Editor:
The reader is right: the brackets need to match of course. Change this: char file_name[256}; to this: char file_name[256];

Steven Sierra Forero  Nov 13, 2012 
Printed
Page 343
line 2 of the example for gets

Delete the line: char *ptr = buffer; [[because ptr is not used in the example]]

Anonymous    May 11, 2012
Printed
Page 343
line 3 words 10 and 11

...attempt to store characters past the end of the of the available.... remove extra "of the"

Note from the Author or Editor:
Page 343, line 3: Change "of the of the" to "of the".

Anonymous  Apr 02, 2013 
Printed
Page 344
section "getwchar", last two sentences of the text paragraph

Change "file" to "stream" and "stdin" (as at getchar), thus: "A return value of WEOF indicates an error or an attempt to read past the end of the input stream. In these cases the function sets the error or end-of-file flag for stdin as appropriate."

Anonymous    May 11, 2012
Printed
Page 345
text paragraph after the description of the structure struct tm, and before the "Example" heading

Change "as a" to "in", move "usually", and add a comma, thus: "The type time_t is defined in time.h, usually as equivalent to long or unsigned long."

Anonymous    May 11, 2012
Printed
Page 350
section "isdigit"

Delete one and a half sentences, which span a paragraph break: "The results depend on the current locale setting for the localization category LC_CTYPE, which you can query or change using the setlocale() function. In the default locale C, " The resulting single text paragraph should read: The function isdigit( ) tests whether its character argument is a digit. isdigit() returns a nonzero value (that is, true) for the ten characters between '0' (not to be confused with the null character, '&#65533;') and '9' inclusive. Otherwise, the function returns 0 (false).

Anonymous    May 11, 2012
Printed
Page 351
Example in the isfinite section

double vsum( int n, va_list argptr ) should be double vsum( int n, ... ) and 'va_list argptr' should be declared inside the function.

Note from the Author or Editor:
Amending the first line of the example, and inserting a line after the third line, the first five lines of the example should read as follows: double vsum( int n, ... ) // n is the number of arguments in the list { va_list argptr; double sum = 0.0, next = 0.0;

Anonymous  Aug 28, 2009  May 11, 2012
Printed
Page 358
section "isunordered"

In the "isunordered" section heading line, add the "C99" tag at right.

Anonymous    May 11, 2012
Printed
Page 362
section "iswblank"

In the "iswblank" section heading line, add the "C99" tag at right.

Anonymous    May 11, 2012
Printed
Page 364
section "iswdigit", second paragraph of descriptive text

Delete the first two lines of the paragraph and capitalize the "The" that follows. The resulting second paragraph should read: The digit wide characters are L'0' (not to be confused with the null character L'&#65533;') through L'9'. The iswdigit() function returns a nonzero value (that is, true) if the wide character represents a digit; if not, it returns 0 (false).

Anonymous    May 11, 2012
Printed
Page 365
section "iswlower", last sentence of first paragraph of descriptive text

Change "islower()" to "iswlower()".

Anonymous    May 11, 2012
Printed
Page 368
top (above the section header "iswxdigit")

At the end of the "See Also" list for isxdigit, delete the following repeated phrase: "; the extensible wide-character classification function, iswctype()" I.e., the "See Also" list should end after "setlocale()".

Anonymous    May 11, 2012
Printed
Page 375
bottom, sectiom "log1p"

In the last two lines, which show the prototypes of log1pf() and log1pl(), delete the "(C99)" tags at right. (Because *all three* function variants are C99, as marked in the section header!)

Anonymous    May 11, 2012
Printed
Page 376
section "log2"

Delete the "(C99)" tag to the right of these two function prototypes: float log2f( float x ); long double log2l( long double x );

Anonymous    May 11, 2012
Printed
Page 380
Example

Change lines 8, 12, and 17 of the example code. Change from this: 8 while ( NULL != fgets( buffer, fp_in ) ) 9 { 10 if ( head == NULL ) /* Chain not yet started; add first link */ 11 { 12 head = malloc( sizeof(struct linelink)); 13 if ( head != NULL ) 14 { 15 head->line = malloc( strlen( buffer ) + 1 ); 16 if ( head->line != NULL ) 17 strcpy( head->line, buffer ); ... to this: while ( NULL != fgets(buffer, sizeof(buffer), fp_in )) { if ( head == NULL ) /* Chain not yet started; add first link */ { head = tail = malloc( sizeof(struct linelink)); if ( head != NULL ) { head->line = malloc ( strlen( buffer ) + 1 ); if ( head->line != NULL ) { strcpy( head->line, buffer); head->next = NULL; }

Anonymous    May 11, 2012
Printed
Page 383
section "mbrtowc", second text paragraph

Add the following sentence at the end of the paragraph: "If no valid multibyte character is found within the maximum length specified by the maxsize argument, mbrtowc() returns -2." [[maxsize in monospaced italics; mbrtowc in monospaced font.]]

Anonymous    May 11, 2012
Printed
Page 395
subsection "Conversion specification syntax", after the

syntax statement: Change the first descriptive sentence to include '#' in the possible flag characters, thus: "The flags consist of one or more of the characters +, ' '(space), -, 0, or #."

Anonymous    May 11, 2012
Printed
Page 397
just below the middle of the page

Change "256" to "512" in the example code and in the output, thus: printf("512 times pi cubed equals %.2e, or %.2a. ", bignumber, bignumber); This printf() call produces the following output: 512 times pi cubed equals 1.59e+04, or 0x1.f0p+13. - Same location, first line of text after the example's output edited above: Delete "of [Greek letter pi] ", thus: "The first representation shown here, produced by" etc.

Anonymous    May 11, 2012
Printed
Page 399
section "putc", subsection "See Also"

Delete "C99 ", leaving "the functions to read and write"

Anonymous    May 11, 2012
Printed
Page 400
section "putchar", subsection "See Also"

Again, delete "C99 ", leaving "the functions to read and write"

Anonymous    May 11, 2012
Printed
Page 412
bottom

The second and third items in the bullet list need to be amended as follows: . A matching failure: a non-whitespace character in the input failed to match the conversion specification or the character in the corresponding position in the format string. . An input failure: no further characters could be read from the input, or an encoding error occurred.

Anonymous    May 11, 2012
Printed
Page 418
section "setvbuf", list item "_IOLBF"

Change to: _IOLBF Line buffered: On read and write operations, characters are placed in the buffer until one of them is a newline character, or until the buffer is full. Then the contents of the buffer are written to the stream. The buffer is also written to the stream whenever the program requests, from an unbuffered stream or a line-buffered stream, input which requires characters to be read from the execution environment.

Anonymous    May 11, 2012
Printed
Page 419
section "signal"

The bullet list should be only three items; the fourth bullet item should be a plain text paragraph.

Anonymous    May 11, 2012
Printed
Page 421
about the middle of the page, the code lines that begin the definition of the function sigint_handler()

Change "char c;" to "int c = 0;" (because tolower() returns int), thus: void sigint_handler(int sig ) { int c = 0; - In the same example, five lines farther down: Change three code lines from this: while (( c = tolower( getchar( ) )) != 'y' && c != 'n' ) ; if ( c == 'y' ) to this: while (( c = tolower( getchar( ) )) != 'y' && c != 'n' && c != EOF ) ; if ( c != 'n' )

Anonymous    May 11, 2012
Printed
Page 424
Under snprintf, first paragraph, last sentence

The sentence says that "sprintf() writes nothing to dest". The sprintf should be snprintf(note addition of "n" to routine name), since this is talking about the behavior of the snprintf routine.

Note from the Author or Editor:
P. 424, section "snprintf", first running-text paragraph, last line, first word: change "sprintf()" to "snprintf()".

Anonymous  Nov 06, 2013 
Printed
Page 433
Table 17-10

The table entry for 'd' occurs twice, before and after 'D'. Delete the second occurrence.

Anonymous    May 11, 2012
Printed
Page 435
top, line 1 of the example

Append a semicolon at the end of the line.

Anonymous    May 11, 2012
Printed
Page 443
middle of page, section "strtoumax", subsection "See Also"

Change first item, "strtoumax()", to "strtoimax()".

Anonymous    May 11, 2012
Printed
Page 444
middle of page, in the example for section "strxfrm"

Change lines 15, 17 and 18 of the code as follows: Line 15: change "originals[i]" to "stringpairs[i].original" Line 17: change "->" to "." Line 18: delete the final semicolon. In other words, change the for-loop from this: 12 for ( int i = 0; i < 8 ; i++ ) 13 { 14 stringpairs[i].xformed 15 = malloc( strxfrm( xformbuffer, originals[i], 1024 ) +1 ); 16 if ( stringpairs[i].xformed != NULL ) 17 strcpy( stringpairs[i]->xformed, xformbuffer ); 18 }; to this: for ( int i = 0; i < 8 ; ++i) { stringpairs[i].xformed = malloc( strxfrm ( xformbuffer, stringpairs[i].original, 1024 ) + 1 ); if ( stringpairs [i].xformed != NULL ) strcpy(stringpairs[i].xformed, xformbuffer); }

Anonymous    May 11, 2012
Printed
Page 444
section "swprintf", in the example, code line 5

Break up the line: static wchar_t buffer[16], sign[2] = L""; into two lines as follows (because sign should not be static): static wchar_t buffer[16]; wchar_t sign[2] = L"";

Anonymous    May 11, 2012
Printed
Page 450
section "toupper"

Change: "The tolower() function returns" to: "The toupper() function returns"

Anonymous    May 11, 2012
Printed
Page 465
line 2

Delete: ",or arrays of wide characters," leaving: "The two strings are equal."

Anonymous    May 11, 2012
Printed
Page 465
section "wcscopy"

In the function prototype, change "s1" to "dest" and change "s2" to "src". In the first line of the descriptive text below that, change "char" to "wchar_t".

Anonymous    May 11, 2012
Printed
Page 471
section "wcsrtombs"

In the function prototype at the top of the section, in the indented line beginning with "size_t", change "len" to "n".

Anonymous    May 11, 2012
Printed
Page 483
section "wmemchr", first line of descriptive text

Change the italic "c" in "with the value of c" to "wc".

Anonymous    May 11, 2012
Printed
Page 484
line 4

Delete "(evaluated as unsigned char) ".

Anonymous    May 11, 2012
Printed
Page 486
bottom, section "wmemset"

In the first line of the descriptive text (third to last line of the page), change "The memset() function" to "The wmemset() function".

Anonymous    May 11, 2012
Printed
Page 487
Table 17-11, last line, right column

Delete ", no string terminator". (Do not change the similar entry two lines higher in the table.)

Anonymous    May 11, 2012
Printed
Page 498
Second paragraph, last line

LIBARY_PATH should be LIBRARY_PATH.

Anonymous    May 11, 2012
Printed
Page 498
Command line example after third paragraph.

The example: $gcc -lm -Wl,-M circle.c circulararea.c > circle.map does not redirect the map file to circle.map because the map output is written to stderr, not stdout. TO FIX: Change the command line example to: $gcc -lm -Wl,-Map,circle.map circle.c circulararea.c In this case the explanatory paragraph following the command line example should read: The option -Wl,-Map,circle.map on the GCC command line passes the option -Map,circle.map to the linker command line, instructing the linker to print a link script and a memory map of the linked executable to the specified file, circle.map.

Anonymous    May 11, 2012
Printed
Page 503
Third paragraph, 1st sentence

"The -Wextra option also warns expressions..." should be: "The -Wextra option also warns about expressions..." ^^^^^

Anonymous    May 11, 2012
Printed
Page 523
second par.

SYMTABS = $(OBJ .o=.sym) must be SYMTABS = $(OBJ:.o=.sym) (Don't put any whitespace behind the colon.)

Anonymous    May 11, 2012
Printed
Page 523
Example 19-4, middle of page

clean: $(RM) $(OBJ) *.sym circle dcircle should read: clean: $(RM) $(OBJ) *.sym circle circle-dbg

Anonymous    May 11, 2012
Printed
Page 523
second paragraph

Example 19-4 will never build symbols. make to stderr: "make: Nothing to be done for 'symbols'. I'm just a beginner with programming so I tried it on three different computers with three different linux distributions (mandrake 8.2 lfs 6.2 and mandrake 10.1). Typed in the example by hand and copied and pasted it from Safari. As far as I can see the problem is with: SYMTABS = $(OBJ .o=.sym). It doesn't expand to the proper value. Also, in the book on page 523, second to last paragraph, it says: $(name: ending=new_ending). Please note the colon. It is different in the example (=without colon). Adapting the example like : SYMTABS = $(OBJ: .o=.sym) also does not work. When I just say: SYMTABS = circle.sym circulararea.sym it works properly.

Note from the Author or Editor:
The problem is that the missing colon in the variable reference with substitution has become a space, which the syntax does not allow. Line 10 in Example 19-4 should read: SYMTABS = $(OBJ:.o=.sym) with no space inside the parentheses. Furthermore, the syntax line before the last paragraph on p. 523 should read: $(name:ending=new_ending) again with no space inside the parentheses.

Anonymous    May 11, 2012
Printed
Page 529
in the paragraph describing the list item ".LOW_RESOLUTION_TIME",

line 4: Change "low-resolution" to "high-resolution".

Anonymous    May 11, 2012
Printed
Page 543
in the paragraph describing the list item ".NOTPARALLEL", last sentence

Change this: "such recursions still run parallel to the present instance, unless their makefiles also contain" to this: "the new instance of make still executes commands in parallel, unless its makefile also contains" [[My error was based on an error in the GNU Make manual. I filed a bug report, http://savannah.gnu.org/bugs/?17701]]

Anonymous    May 11, 2012
Printed
Page 562
example at the top of the page, last three lines of the example

In the third to last line of the example, change "21" to "27", and In the last line of the example, change "14" to "16". The resulting three lines: 1 breakpoint keep y 0x004010e7 in swap at gdb_example.c:27 ignore next 5 hits 3 breakpoint del n 0x004010c0 in main at gdb_example.c:16

Anonymous    May 11, 2012