errata

Departments

Main

About

Errata

FAQ

Compiler Tips

Supplemental Lessons

NCurses

Source Code Files

On-line Book Ordering

[C News]

C All-in-one Desk Reference

Page 43-44

At the top of page 43 the fifth line of code should read:

print("Hello, geek!/n")

That same line is repeated at the top of page 44, where it should read:

printf("Hello, geek!/n");

In both cases, the backslash printed in the book needs to be changed to a forward slash in your code.

Page 51

Second to last paragraph, (bottom left in the box), should read, "The bottom line is that it takes more work for the computer to figure out floating point problems than it does for the computer to work in integers."

Page 74

In the bottom paragraph, the "Tip," the fourth sentence should read, "Sometimes this strategy makes the code less readable for beginners, but it often improves readability for those more experienced in C."

Page 76

The code for subjects.c, line 10 should read:

scanf("%s",subname);

An ampersand is not needed before a string variable name in the scanf() function.

Later on the same page, I write, "The variable must be prefixed by an ampersand." That's technical incorrect. Arrays don't need the ampersand prefix. It doesn't screw anything up by adding them, but the statement I wrote implies something else. Bottom line: for strings or arrays, there is no need to prefix them with a & when use in scanf() functions.

(Also see the entry for pages 365 and 366.)

Page 101

The TICKETS.C program uses the total variable without first initializing it. On some systems, this has the effect of producing an invalid result. This is my problem; using a variable without initializing it is wrong. Sometimes it does work, but there is no guarantee. (Refer to pages 53 & 54 in the book.)

To fix the program, add a new line below the variable declarations and above the first puts() statement:

total = 0;

Page 120

The line at the bottom of the page should read "The += mathematical shortcut . . ." I have it backwards at =+, which isn't correct.

Page 121

The source code demonstrates multiplying a variable by a value and then having the result placed back into the same variable. It doesn't not demonstrate multiplying a varible by its own value.

Page 130

The result of an operation such as a=b is not "always TRUE" as it says in the box. It could be TRUE or FALSE. The result depends on the value of b, which is assigned to a and evaluated by if. So when b is non-zero, the result is TRUE. When b is zero, the result is FALSE. Regardless, the point made in the sidebar is correct: you need two equal signs to compare values, not one.

Page 132

Modify line 13 to read like this:

if(agent==7 && (code=='B' || code=='b'))

Page 155

The hex code for the Yen character (¥) is 0x9D, not 0x9E as listed in the text. Even so, don't expect the code to work for your terminal; not every terminal uses the same code page.

Page 212

The ff at the bottom of the page is supposed to be if, as in:

if(a > b)
    z = a;
else
    z = b;

Page 219-220

The source code listed in the section Where goto Is Perhaps Needed, is missing the updates mentioned in the text. The code is listed properly in this web site's source code area:

http://www.c-for-dummies.com/source.code/middle/grid1.c

Page 288

The sample output of OZ.C (oz6.c on disk) is incorrect. The output shown is what the list looks like before the swap. After the swap, the output should look like this:

Wizard of Oz Database!
Actor              Age   Role 
----------------------------------------
Judy Garland        17   Dorothy 
Ray Bolger          35   Scarecrow 
Bert Lahr           44   Cowardly Lion 
Jack Haley          40   Tin Woodsman 
Frank Morgan        49   The Wizard 
Margaret Hamilton   37   Wicked Witch 

Page 308

The source code for the modification to the MYSTUFF.C program includes the declaration of the input[] variable, but that variable is not used in the code. This is also true for the source listing on page 309 as well.

Feel free to delete the input[] declaration. Though the program runs with it in there, it's wasteful of resources.

Page 343

The scanf() statement is missing a & before the you.inches variable. It should read:

scanf("%d",&you.inches);

The two printf() statements at the end of the program use the %f placeholder incorrectly. They should read, both in the code and later on toward the end of the page:

printf("You are %.1f centimeters tall.\n",you.centimeters);
printf("Paul is %.1f centimeters tall.\n",paul.centimeters);

Note that the code found here does list the correct expressions.

Page 356

Near the end of the code a capital I appears where a little i should be used instead. At the end of the code, the end of the line just before return(0) should be &temp[i];

Incidentally, many professors recommend that you not use I alone as a variable name for this reason, as well as that I is often confused with the number 1.

Page 359

The 11th line of the code should read:

kilometers = miles*KPM;

Page 365

The sidebar at the bottom of the page, "If you don't need an & to read an array's address in C, why does scanf() still need an & in order to read a string" is incorrect. Disregard it.

Page 366

In the second paragraph, the parenthetical statement is incorrect. You do not need to use an & when specifying string variables in a scanf() function.

Page 367

Line 6 in the code should read:

short int *pa;

Obviously if *pa is to reference the short int array variable they must be of the same type.

Page 407

The sentence in the middle of the page should reference pointer variable c and not p:

This type of construction shouldn't be entirely alien to you. You should recognize that *c is a pointer, which means that c contains a memory address.

Page 408

This sentence is incorrect:

In the case *p++, the ++ operator is higher on the list so it increments memory location p one chunk before the * operator fetches a value.

The *p part of the operator is bound more tightly than the ++, as described (correctly) in Table 4-1.

Page 440

In Figure 6-5, the *(*(array+0)+0) notation above bashful\0 is repeated. It should instead read *(*(array+0)+0), *(*(array+0)+1), *(*(array+0)+2), and so on.

Page 443

In Table 6-1, the last entry is incorrect. The 1 should be replaced with the letter a, like this:

**(array+a)+b is the same as array[a][0]+b which translates as the value of the first item in the array referenced by a, plus the value of b. Note that b is not used to calculate an address, but rather it's added to the value found at the address.

Page 504

Some versions of GCC recognize select() as an existing function — and it is! It's used for "synchronous I/O multiplexing" (whatever that is). So with some compilers you may need to rename the select() function as listed on page 504 in the main() function. I recommend using bselect() instead:

bselect();

On page 505 in LOTTO.H:

void bselect(void);

And in SELECT.C on page 507:

void bselect(void)

You do not need change the name of SELECT.C, only the name of the function select().

Page 536

My editor got a bit overzealous when correcting the PigLatin program's output. Each word is Initial Caps in the output. The output should read:

Something clever
Omthingsay Levercay

If you'd like to have the code keep the same case as the input text, then feel free to make that modification on your own!

Page 587

If you're using Mac OS X, then the stat() function appears to return zero for the file size in the FILEINFO.C program. This is because OS X stores the file size in a double-long int. When you use %d to display the value, it probably shows zero because of the way a double-long is stored in memory. Use %lld instead:

printf("File size is %lld bytes\n",fbuf.st_size);

(Those are lower case L characters, not ones, in the placeholder.)

Page 626

The sample code was copied improperly. It should read index++; not index--; as shown in the middle of the page.

Page 644

The chunk of text needs to be inserted after the while(ch != 'Q') statement. The statement mentioned in the book is while(ch != 0), which is incorrect.

Page 673

Step 2 is different for Windows 2000, which uses a local documents folder as the main personal file storage thingy. So use this command instead:

cd "local documents"

(The double quotes are not optional.)

You'll then see the prompt reflect this:

C:\Local Documents>

Thanks to reader Cort for pointing this out. Also, reader James notes that a My Documents folder can be found, though it's location is:

Documents and Settings\Administrator\My Documents

I apologize for this confusion; it's been a long time since I had a Windows 2000 computer to play around on.

Page 696

The answer for Exercise 1.8.3 (MOON4.C) uses the wrong placeholder to display the value of the SPEED constant. The %d placeholder should be used instead of %f. Line 14 in the source code should read:

printf("Traveling at %d kph, ",SPEED);