Start any video training course for FREE. More than 500 to choose from. Learn more
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
Printed Page 113
page 113

the link on page 113(http://oreillyhfc.appspot.com/map.html) was not working

Anonymous  Aug 11, 2015 
Printed Page 91/93/94
Bottom left function (page 91/93) & the main function in the page 94 code review

The same erroneous code appears in all three places. 1: int main() 2: { 3: char search_for [80]; 4: printf ("Search for: "); 5: scanf ("%79", search_for); 6: search_for [ strlen(search_for) - 1 = '\0' ]; 7: find_track (search_for); 8: return 0; 9: } Using this code as the main function in the program on page 94 and entering for example the string "my" will return a result as if the user had entered only "m". The program will search for a string one char shorter then the one the user entered. The problem is line 6 in the current program. It replaces the last character entered by the user with the '\0' (null) character. After reading the confirmed errata it seems like this piece of code (in the first printing of the book) used fgets() on line 5 instead of scanf(). As i understand it the fgets function adds a newline char ('\n') automatically to the end of the string the user enters. Line 6 in the current code was intended to overwrite this newline char with the NULL char. But since scanf() does not add a newline char the result is that the last character in the string the user entered is overwritten instead. If line 6 is omitted the program works as intended.

Gustav Bergstrand  Jul 29, 2015 
PDF Page 483
while loop of main function

when comparing the string received from the client, strncasecmp() is used incorrectly example: if (strncasecmp("Who's there?", buf, 12)) should be if (strncasecmp(buf, "Who's there?", 12) != 0) since strncasecmp() returns 0 if the given "strings" are equal, ignoring case, and the given integer gives a limit for the first string not the second.

Anonymous  Jun 08, 2015 
PDF Page 497
Paragraph "Send signals with raise()"

"Sometimes you might want a process to send a signal to itself, which you can do with the raise() command" should be changed into Sometimes you might want a process to send a signal to itself, which you can do with the raise() FUNCTION.

Paolo Piersanti  Mar 25, 2015 
PDF Page 493
middle of the page

"The sigaction() function will return –1 if it fails and will also set the errno function" should be corrected into "The sigaction() function will return –1 if it fails and will also set the errno VARIABLE"

Paolo Piersanti  Mar 24, 2015 
PDF Page 167
Example

Book says: printf("The value of FLT_MIN is %.50f\n", FLT_MIN); This is the lowest value. No it is not, this is: printf("The value of FLT_MIN is %.5f\n", -FLT_MAX);

Koray Tugay  Mar 19, 2015 
Printed, PDF Page 163
2nd Example

Example is: int x = 100000; short y = x; print("The value of y = %hi\n", y); It should be printf not print.

Koray Tugay  Mar 19, 2015 
Printed Page 93
Top left function and top right function

On page 93 the mistakes in the top left and top right functions are mentioned by the authors, but there is no comment for the following line: search_for[strlen(search_for) - 1] = '\0'; I assume this line was added to null terminate the search_for string, but the string has already been null terminated by the previous line (fgets()). If the search_for string is not null terminated, strlen() can not be run on it since it requires there to already be a null terminator in the string. Running strlen() on a string that is not null terminated could cause strlen to run outside the allocated array until it accidentally hits a 0 somewhere in memory. For example I tried running strlen() on a "string" of length 2 that was not null terminated and in my debugger it reported the length as 20. Furthermore, it is incorrect to subtract 1 from the result of strlen(). Let us assume that we have the following null terminated string: ['A', 'B', 'C', '\0'] strlen() on this string would give 3 since strlen() does not include the null terminator. Subtracting 1 from this result would give 2. But adding a null terminator to index 2 would overwrite 'C'. That is probably not the intention?

Erlend Andreas Lorentzen  Feb 08, 2015 
Printed Page 93
Bottom left function

The bottom left function on page 91/93 has several errors / faulty assumptions. One of these are already mentioned in the unconfirmed errata. The code in question is as follows: ========================== char search_for[80]; // line 1 printf("Search for: "); // line 2 scanf("%79s", search_for); // line 3 search_for[strlen(search_for) - 1] = '\0'; // line 4 find_track(search_for); // line 5 return 0; // line 6 ========================== First of all, line 4 is not needed since scanf adds a null terminator at the end of the string automatically. But even if scanf did not add a null terminator, this code would not work since search_for[80] has not been initialized and contains "garbage" and is not a valid C-string until a null terminator is added. If there was no null terminator added, strlen(search_for) would not work, because it relies on there being a null terminator in the string in order to check the length and that would make the effort of adding a null terminator pointless. But even if it worked without the null terminator this would still not give the correct behavior, since it overwrites the last string character with a null terminator, not the last array position. You are using strlen as if it was sizeof. But strlen does not include the null terminator it is the length of the string not the size of the array: If we assume that a string of length 79 was written to the search_for array so that index 0 through 78 corresponded to a valid character (and index 79 being the final index position where one would add a null terminator), then: strlen(search_for) - 1 => 79 -1 => 78 (index of null terminator) But index 78 is occupied by a valid character. Index 79 would be the first array index after the last valid character and it would make sense to add a null terminator there if scanf did not add a null terminator.

Erlend Andreas Lorentzen  Feb 08, 2015 
PDF Page 93
bottom left function

The latest version of the ebook prints the following scanf("%79s", search_for); search_for[strlen(search_for) - 1] = '\0' The above line is not necessary to add a null char since we are using scanf operator.

Ng Peng Hon  Jan 20, 2015 
PDF Page 37
Check if card val is in range

The proposed check is: if ((val < 1) || (val > 10)) printf("I don't understand that value") but in the switch above it we have: case 'A' val = 11; which means the card counter claims it doesn't understand Aces as input. Suggest changing case 'A' such that val = 1.

Grahame Gardiner  Jan 17, 2015 
Printed Page 664
7th line of text from the top of page including title.

Incomplete sentence (look at the words "items" and "And": "...The only difference is that instead of laying out items And just like the ListView, it uses a"

Shannon Boggs  Dec 09, 2014 
PDF Page 88
Sharpen your pencil answer

This solutions shows: strstr() it should show: strstr() and strlen()

Anonymous  Oct 19, 2014 
PDF Page 37
End of the while condition of Exercise Solution

The while condition reads: } while(card_name[0] != 'X') It's missing the ; at the end of the line. It should read: } while(card_name[0] != 'X');

Anonymous  Oct 19, 2014 
PDF Page 274
Program Output

The output from the code void display(island *start){ island *i = start; for(; i != NULL; i = i->next){ printf("Name: %s open: %s-%s\n", i->name, i->opens, i->closes); } } displayed on Page 275 is missing a \n between %s and open:

Bill  Sep 06, 2014 
Printed Page 465
Bottom, Bullet Points section, 5th bullet point

5th bullet point should have signal() replaced by sigaction() as that has been the method demonstrated for changing/registering the new handler for a signal in the preceding pages. Point should read: "Handlers can be replaced with the sigaction() function"

Frank Hernandez  Jul 28, 2014 
Printed Page 445
Bottom, "parent" graphic caption

Parent graphic caption should read: 'The parent connects the read end to the Standard Input' (instead of Standard 'Output'). Parent descriptor table graphic correctly shows the 'Standard Input' as being effected by dup2(fd[0], 0); statement. Caption needs to be corrected to 'Standard Input'

Frank Hernandez  Jul 25, 2014 
PDF Page 548
7th paragraph

The variable, "$@", is duplicated in the sentence describing the example make task. The second instance of "$@" should be "$^". It should read: "Then, the recipe will run a gcc command to create the target fred (given by the special symbol $@) using the given dependency (given by $^."

Jeff Ramnani  Jul 21, 2014 
PDF Page 215
Last line

The books states: "If you have a Mac and want to make your plant really talk, you can download a script from the Head First Labs website that will read out the stream of serial data: www.headfirstlabs.com/books/hfc" However, that link does not work: "Page Not Found Sorry, that page does not exist."

Sarah  Jul 07, 2014 
PDF Page 113
map.htlm

v2 API no longer available

Anonymous  Jun 24, 2014 
Printed Page 12
To the bottom right

C coders after call this the NULL character should be C coders often call this the NULL character

Deepu Thomas  Jun 09, 2014 
PDF Page 69
Heading-Anyone for three-card monte?

You were saying that the code would give an error while it was compiling but on my machine it compiled successfull and also with desired output. What is the reason please clarify me I running windows 8. and using Developer command prompt for vs 2012 for compiling c programs.

Nasim Royal Beg  Jun 03, 2014 
PDF Page 4
scanf("%19s", ex);

Missing &

Jean Doyon  Oct 24, 2013 
Safari Books Online 375
Under 'Compiling the elliptical program'

I also noticed that the first command says \include where it should say ./includes (dot, forward slash, and with an s at the end).

Linda Pescatore  Sep 21, 2013 
Safari Books Online 375
Under 'Compiling the elliptical program'

Again, there is no dot before the slash in the statements. I am not sure whether this is intentional but it does say the code is the same as before, and the previous code for static linking had the dot.. Also, why switching to back slashes when before we used forward slashes?

Linda Pescatore  Sep 21, 2013 
Safari Books Online 374
code after first paragraph

The line gcc -I/includes -fPIC -c hfcal.c -o hfcal.o lacks a dot before /includes. The code may work depending on how someone's files are set up. The previous example about static linking did use the dot there. Or, there should be instructions to move the includes directory if that was the intent.

Linda Pescatore  Sep 21, 2013 
PDF Page 322
United States

In the arrays, one of the "likes" is "art." I'm not sure if it's intentional but the function "int arts_theater_or_dining" searches for a match with "arts." Peter likes art, but he is not found in this search, although he probably should be.

Linda Pescatore  Sep 12, 2013 
Printed Page 331
compare_names function

A "better" solution for the compare_names() function: int compare_names(const void* a, const void* b) { char* str_a = *(char **)a; char* str_b = *(char **)b; return (strcmp(str_a, str_b)); } as this version does not require the additional dereference, and more closely resembles the previous solutions. I would then move the annotation, "We need to use the * operator to find the actual strings", to point to the * operator in the right hand operand in the first line.

Patrick Waugh, M.A.  Aug 27, 2013 
PDF Page 200
United States

I think that this mistake hasn't been caught because we readers don't see the thruster and launch files to try and make a makefile for. But I tried making a makefile for my encrypt.c and file_hider.c files (the latter I made myself, it's the other program that would use the encrypt file). I followed the template on page 200, and wondered why it didn't work. It only did the first command. I found http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html by googling and realized the targets were in the wrong order. The make file should only complete the first command, so the final target has to be first, not last. The launch rule must come first, then launch.o, then thruster.o. When I reordered my makefile, it worked great.

Linda Pescatore  Aug 27, 2013 
PDF Page 182
United States

Not sure if this is a cygwin issue, but it didn't happen when i tried the example in linux. The message_hider doesn't respond with the encryption after each line is input, unless you add this after main: setbuf(stdout, NULL); I already had the \n to \0 substitution but it wasn't enough.

Anonymous  Aug 25, 2013 
PDF Page 111
United States

I found the solution to the error I posted before about the ragged formatting, well actually someone at Stack Overflow figured it out. Because I created the .csv file on Windows, Cygwin and Linux didn't like my line endings. I added \r before \n in the scanf parameters and it straightened itself out.

Linda Pescatore  Aug 22, 2013 
PDF Page 111
United States

I copied geo2json and gpsdata.csv exactly from the book. Geo2json works fine with data from keyboard but when I redirect stdin to the file, something strange happens at the beginning of each line except the last. I am using Cygwin. $ ./geo2json < gpsdata.csv data=[ '}, itude: 42.363400, longitude: -71.098465, info: 'Speed = 21 '}, itude: 42.363327, longitude: -71.097588, info: 'Speed = 23 '}, itude: 42.363255, longitude: -71.096710, info: 'Speed = 17 '}, itude: 42.363182, longitude: -71.095833, info: 'Speed = 22 '}, itude: 42.363110, longitude: -71.094955, info: 'Speed = 14 '}, itude: 42.363037, longitude: -71.094078, info: 'Speed = 16 '}, itude: 42.362965, longitude: -71.093201, info: 'Speed = 18 '}, itude: 42.362892, longitude: -71.092323, info: 'Speed = 22 '}, itude: 42.362820, longitude: -71.091446, info: 'Speed = 17 '}, itude: 42.362747, longitude: -71.090569, info: 'Speed = 23 '}, itude: 42.362675, longitude: -71.089691, info: 'Speed = 14 '}, itude: 42.362602, longitude: -71.088814, info: 'Speed = 19 '}, itude: 42.362530, longitude: -71.087936, info: 'Speed = 16 '}, itude: 42.362457, longitude: -71.087059, info: 'Speed = 16 {latitude: 42.362385, longitude: -71.086182, info: 'Speed = 21'} ]

Linda Pescatore  Aug 21, 2013 
PDF Page 527
third paragraph, "Events"

"fires her canyon" should be "fires her cannon"

David Demko  Jun 14, 2013 
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 Corbire  Aug 18, 2012 
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