Head First C

Errata for Head First C

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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.


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



Version Location Description Submitted By Date Submitted
PDF Page i
Cover

Um... can we put an 'Early Release' cover on this thing? When I'm squinting at covers in iBooks, it looks like a thesis or a calibre conversion. Yes, I do squint at the covers in iBooks.

Leo M.  Feb 22, 2012 
PDF Page 9
item 3 using "./" to run object module

I am brand new to C. So I follow the book's instructions closely. I did not use the "./" in front of my compiled object module for Windows. I got a "module not found" message. Using "./" my module executed. I also found that it ran equally well with no ".exe" extension and with it. I am doing all this exclusively on my Windows 7, 64-bit laptop. My install was to C:\cygwin\ I am wondering if the cygwin version I installed is responsible for the difference. I installed the latest cygwin version 1.7.22 in November 2012.

Tom Bullock  Dec 22, 2012 
Printed Page 13
Top right of page

Q: Are there any differences between string literals and character arrays? A: Only one: string literals are constant. The A is incorrect. Strings literals are constant and enforce zero termination whereas character arrays have no "ability" to enforce zero termination and it is necessary for the programmer to ensure zero termination. Some review of colon usage may be recommended: If the introductory phrase preceding the colon is very brief and the clause following the colon represents the real business of the sentence, begin the clause after the colon with a capital letter.

Rob Wehrli  Apr 29, 2012 
Printed Page 37
case 'X' : continue

the errata of correction of while (card_name[0]!='X') { ...code... } to a do { ...code... } while (card_name[0]=!'X') never hits the switch case 'X': continue; loops forever case 'x' return 0;

sapien  Sep 02, 2012 
PDF, ePub, Mobi Page 37
Switch statement case A

case 'A' in the switch statement sets variable "val" to 11 triggering the error message created by the "if ((val < 1) || (val > 10))" statement. Is this desirable? Meaningless?

Bryan Dobberstein  Mar 13, 2013 
PDF Page 42
last paragraph

The stock level had dropped to 100 glasses I think this should say "dropped to 90 glasses".

Anonymous  Mar 02, 2012 
PDF Page 45
First paragraph, last sentence

"...player wants to travel southeast, that means her latitude will go DOWN, and her longitude will go UP: Since the 'game' takes place in the Bermuda "Rectangle," it seems to indicate we're in the western hemisphere. Therefore, the direction of the number and the values shown are confusing, to say the least. While -63 is closer to zero than -64, neither are valid/logical longitude values, at least on Earth. ;-) Moving east will make the Longitude number go UP only while one is EAST of the Prime Meridian and WEST of 180*.

Jim Chaffin  May 08, 2012 
Printed Page 46
Point 1,2 & 3 under section "C sends arguments as values"

In all the mentioned points, variable named 'longitude' is said to have the value 32. But actually it is the variable named latitude that has value of 32. For example, Point 1 says : "Initially, the main() function has a local variable called longitude that had value 32. this should actually be : "Initially, the main() function has a local variable called latitude that had value 32.

jainanupam  Aug 15, 2012 
PDF Page 94
code example

The code, as input, doesn't account for the newline character that will be input by the user. They will need to call strtok(). So, instead of: int main() { char search_for[80]; printf("Search for: "); fgets(search_for, 80, stdin); find_track(search_for); return 0; } It should read: int main() { char search_for[80]; printf("Search for: "); fgets(search_for, 80, stdin); strtok(search_for, "\n"); find_track(search_for); return 0; }

matthewsopha  Mar 14, 2012 
Printed Page 94
First annotation

The first annotation of the code indicates the stdio.h file is required for the printf() and scanf() functions but the scanf() function isn't used in the code - fgets() is used instead. Suggest changing the annotation to remove the reference to scanf() and replace it with fgets().

Amanda Williams  Feb 15, 2013 
Printed Page 94
Code, main function

Regarding the fgets(search_for, 80, stdin)-newline bug, I don't seem to be able to reproduce it using scanf("%79s", search_for); - isn't that a better workaround than the proposed in the current errata?

Emil Tullstedt  Apr 28, 2013 
PDF Page 96

It would be helpful to have a link to the GPS csv data available for the examples in Chapter 3.

Anonymous  Feb 26, 2012 
PDF Page 113
Sidebar

1. Line 56 of the map.html file should read: if ((lng < -180) || (lng > 180)) { 2. Google has invalidated the old API key used in the map.html file. A new v2 API key needs to be generated. The old API key appears on lines 12 and 16. 3. No instructions for how to get the map.html file were provided. The following works: wget http://oreillyhfc.appspot.com/map.html or curl -C - -O http://oreillyhfc.appspot.com/map.html

BarryBrown  Sep 18, 2012 
Safari Books Online 139
Code snippet

The code is missing an fclose() for the "in" stream. Same error on pages 140, 143 and 145.

Thomas Corbière  Aug 07, 2012 
Safari Books Online 141
1st figure

Aren't arrows missing between the annotations and the command line?

Thomas Corbière  Aug 07, 2012 
Safari Books Online 147
1st annotation

"If you run elvises.txt" should be changed to "If you run elvises.csv".

Thomas Corbière  Aug 07, 2012 
Printed Page 149

'optind' is described as "the number of strings read from the command line to get past the options." This is too vague in wording. It should say that this variable is the "option index" and that it is initially set to '1' and is incremented by 1 for every 'option' argument encountered. Leaving the index at the first argument following any options that may have been processed. The phrase "get past the options" is too vague in this context. It doesn't really describe "why" the following is necessary: argc -= optind; argv += optind; Thanks.

Eric Hutchins  Jan 13, 2013 
Safari Books Online 165-166
exercise code

Remove the semicolon at the end of "add_with_tax(float f);".

Thomas Corbière  Aug 10, 2012 
PDF Page 167
"Data Type Sizes Close Up" code

The printf conversion character for sizeof on both int and float is incorrect. "An int takes %z bytes\n" throws a warning (warning: unknown conversion type character 0x20 in format ), the conversion character(s) should be %zu. It should read printf("An int takes %zu bytes\n", sizeof(int)); otherwise you get nothing for the bytes.

Michael Hans  Sep 06, 2012 
Safari Books Online 182, 186
encrypt function

Remove the unused variable "char c".

Thomas Corbière  Aug 10, 2012 
Safari Books Online 186
3rd paragraph

"to the actual encrypt() function in encrypt.h" should be replaced by "to the actual encrypt() function in encrypt.c".

Thomas Corbière  Aug 10, 2012 
Safari Books Online 200
1st code snippet

Aren't arrows missing between the annotations and the code snippet?

Thomas Corbière  Aug 10, 2012 
PDF Page 218
First code sample

Inside the function label(...) there is a call to printf(). In this call, the "age" and "teeth" parameters are passed in reverse order from how they show up in the format string.

B. Garvelink  May 06, 2012 
Safari Books Online 220
3rd No Dumb Questions

"in the string" should be replaced by "in the struct".

Thomas Corbière  Aug 10, 2012 
Safari Books Online 249
3rd code snippet

".weight for the .amount" should be replaced by "".weight for the union".

Thomas Corbière  Aug 09, 2012 
PDF Page 252
Mixed-Up Mixers Solution

Out of the three definitions rejected as solutions, two of them seem to be correct, they are: margarita m = {2.0, 1.0, .citrus.lemon=2}; margarita m = {2.0, 1.0, 0.5};

Dipyaman  Dec 27, 2012 
Safari Books Online 269-270
Wording of "Sharpen your pencil"

" from one of piece of data" should be replaced by " from one piece of data".

Thomas Corbière  Aug 09, 2012 
Safari Books Online 271
1st figure

It looks like something is missing but I don't know what.

Thomas Corbière  Aug 09, 2012 
Safari Books Online 273
1st picture

The arrows between the islands are not displayed properly.

Thomas Corbière  Aug 09, 2012 
PDF Page 285
anywhere

Pages 285 and 286 introduce the strdup() function, but neglect to mention it's declared in string.h. GCC will complain about the implicit declaration and still compile a working executable, other compilers may not be so forgiving. The text should mention which header to include.

Barend Garvelink  May 14, 2012 
Safari Books Online 295-296
3rd description

"you could use to me" should be replaced by "you could use me".

Thomas Corbière  Aug 18, 2012 
Safari Books Online 362
2nd make file rule annotation

"This creates the object from" should be replaced by "This creates the object file from".

Thomas Corbière  Aug 18, 2012 
Safari Books Online 366
2nd code snippet

"#include <stdio.h>" could be removed because the main function doesn't use any I/O function.

Thomas Corbière  Aug 18, 2012 
PDF Page 374
3rd paragraph

The point and purpose of the "Do this!" instruction regarding the -fPIC flag is nonobvious. Why should I "Do this!"? What am I looking for? The accompanying "Geek bits" blurb suggests it doesn't matter, just pass the compiler flag for portability.

Barend Garvelink  May 19, 2012 
PDF Page 376
bottom of page

In bottom of page 376 there box for linux to change the library variable to /libs like this: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/libs but there is minor error in it path should be "./libs" that is export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./libs

Anonymous  Jun 27, 2012 
Safari Books Online 377
Using MinGW

"PATH="%PATH%:C:\libs"" should be replaced by "PATH="%PATH%;C:\libs"" as Windows is using semicolon to separate paths.

Thomas Corbière  Aug 18, 2012 
Safari Books Online 377
Using Cygwin

"If you’re compiled" should be replaced by "If you’ve compiled".

Thomas Corbière  Aug 18, 2012 
Printed Page 400
sprintf

The echo command doesn't work properly due to new line characters. One is after time, one is at the end. These 2 lines should fix it. comment[strlen(comment) - 1] = '\0'; cmd[strcspn(cmd,"\n")] = ' ';

Anonymous  Jan 19, 2013 
Safari Books Online 412
Wording of the exercise

All the code after the candidate code area should be removed because it will never be executed. either the exec() succeeds and the process is replaced or the exec() failed and the process will be stopped in the if statement.

Thomas Corbière  Aug 17, 2012 
Safari Books Online 432
Geek Bits

"&1 means “to the Standard Input.”" should be replaced by "&1 means “to the Standard Output.”"

Thomas Corbière  Aug 17, 2012 
Safari Books Online 436
Did you get the right answer?

This seems to answer an unasked question.

Thomas Corbière  Aug 17, 2012 
Safari Books Online 453
3rd paragraph

"errno function" should be replaced by "errno variable".

Thomas Corbière  Aug 17, 2012 
Printed Page 454
United States

error handling function is diediedie(), but catch_signal() is called in main() with handle_interrupt, which does not exist.

Yitzchak Schaffer  Jul 10, 2012 
Safari Books Online 455
2nd paragraph

"handle_interrupt()" should be replaced by "diediedie()".

Thomas Corbière  Aug 17, 2012 
Safari Books Online 461
Annotation of catch_signal()

"signal()" should be replaced by "catch_signal()".

Thomas Corbière  Aug 17, 2012 
Safari Books Online 479
bind_to_port() function

"htons(30000)" should be replaced by "htons(port)". Annotation about port 30000 could be removed too.

Thomas Corbière  Aug 17, 2012 
Safari Books Online 490
Code snippet in the terminal

"http/1.1" should be in capital letters "HTTP/1.1" according to RFC2616. This should also be corrected in the explanation of the GET command on the same page. On the class attribute of the html element, add the missing equals sign.

Thomas Corbière  Aug 17, 2012 
Safari Books Online 493
Annotation for freeaddrinfo()

In "freeaddrinf0()", replace the number '0' with the letter 'o'.

Thomas Corbière  Aug 17, 2012 
ePub Page 2780
2nd zoomable screenshot

Kindle version, loc 2780, the Case of the Magic Bullet. Second zoomable screenshot should say 'Masked raider is DEAD!, Jimmy is DEAD!'

Peter Gustafson  Sep 03, 2012