Bugs in A to Z of C

This is the errata page for the book A to Z of C. If you want to submit any grammatical or technical errors visit the bug reporting page!

Our sincere thanks goes to all the people who have reported the following errors!

Page No. Chapter/ Section Bug Type Comment Erroneous Text Fixed (Corrected) Text Reported By Date Status
  Contents Grammar
Use proper English.  Really.  When I see
 section titles like these,
  4.1 Myth & Mistakes
  4.2 Tips for better Programming
  4.2.3 How to code better?
  13.1 Where to contest?
it just makes me think that I'd 
better prepare for a rough ride.
  4.1 Myth & Mistakes
  4.2 Tips for better Programming
  4.2.3 How to code better?
  13.1 Where to contest?
 4.1 Myths and Mistakes
 4.2 Tips for Better Programming
 4.2.3 How to Code Better
 13.1 Contests
    Acknowledged
  2 Grammar Use proper English. Seriously. The first paragraph is all messed up. And this paragraph is still awkward!
  C is often referred to as a 'systems programming language' because it is used for writing compilers, editors, and even operating systems. C was developed and implemented on the UNIX operating system on the DEC PDP-11, by Dennis M. Ritchie. It evolved in 1971-73 from the B language created by Ken Thompson, which evolved (in 1969-70) from Martin Richards' language BCPL.     Acknowledged
  2 (Table) Grammar Your "Timeline" table displays without a bottom bar on page 1. And of course it's got a lot of spelling and grammar errors, but I'm tired of correcting those.         Acknowledged
  3 Technical Your example of Indian Hill style seems to have a mistake: I think the 'int' in front of 'foo' should be aligned vertically with 'foo', not indented by one space.         Acknowledged
  3 Technical While it's tempting to flaunt your own particular coding style in your own publication, I doubt you'll find many programmers who will agree with all of your style's decrees. (The StudlyCaps naming convention for functions seems weird to me, for example.) So it doesn't really seem worth it to make style such a big part of your book.         Acknowledged
  9.3 Technical Your GCD (Greatest Common Divisor) algorithm only works for positive a,b, and crashes if b is zero.         Acknowledged
  9.4 Technical Dispose with the amazed tone. It's not like you've never seen an exponentiation routine before. And given exp() and log10(), I think nobody's ever going to use a user-defined exponentiation routine in real code anyway. Also, crashes if x==0, n<0. Even if you don't fix the problem, you should point out somewhere that it exists, and warn the user not to call these functions with invalid input.         Acknowledged
  9.5 Technical getchar() returns 'int'         Acknowledged
  9.7 Technical An array of single-character strings is overkill. Rewrite this function. Preferably, to use printf("%X", n);         Acknowledged
  9.8 Suggestion Don't you think three nearly-identical functions is enough?         Acknowledged
  10.1 Technical This is not a reason to choose C; it's a reason to choose assembler. The macro you supply is not guaranteed to work in C, even if you fix the syntax error (not enough closing parentheses.         Acknowledged
  10.2 Technical This is a very inefficient prime-number checker. For one thing, you're calculating sqrt((double)n) every single time through the loop...the whole 'flag' variable is just silly. I don't care if you think it's "good programming" to avoid break statements - that's what C uses them for, and if you don't like it, you might consider using Pascal. (It probably slows your code down, too.)...But when the number is divisible only by 99991 (i.e., is not divisible by 2), your loop checks it for divisibility by twice as many numbers as necessary. Solution: check for divisibility by 2 separately, and then check all the odd numbers.  
The fixed code I'm suggesting looks like this:

int IsPrime ( int n ) /* checks for prime */
{
   int i;
   int limit;
   if (n <= 1) return 0;
   if (n <= 3) return 1;
   if (n % 2 == 0) return 0;
   limit = (int) sqrt(n);
   for (i=3; i <= limit; i+=2)
     if (n % i == 0)
       return 0;
   return 1;
}
    Acknowledged
  10.7.1 Technical You wrote "(here we get ab)" when you probably meant "(here we get atemp)". You might want to consider what would happen were the user to call swap(int, i, f). How could you fix this problem? And your XOR version, while avoiding the usual UB, still has more bugs than the sensible version. Besides, you've already celebrated your L33Tness in section 10.6—no need to repeat yourself here.         Acknowledged
  10 (Projects) Technical I'm sure that at least Dennis Ritchie and Brian Kernighan have solved all the problems in K&R. I wouldn't be surprised if Richard Heathfield has done most of 'em, too. (Who's the one with all the solutions on his web page?)         Acknowledged
  11 Technical / Suggestion Why have a one-page chapter that doesn't say anything? At the least, you should present a quine program written in pure ISO C (I can send you one if you like); you should explain why you think this sort of thing is important (code-data equivalence, perhaps?); you might refer the interested reader to Ken Thompson's ACM lecture or to another good source of quine-related puzzles. Quines are a lot of fun, but why waste time with trivial ASCII-based examples when there are much more fundamental ways to create them?         Acknowledged
ch05.pdf5.3Technical
one, is not a valid argument for exit().
exit(1) is not standard C.
Fri Sep 26 2003, 06:54:48 AM ISTAcknowledged
ch08.pdf8.1 strlenTechnical
Your strlen is all wrong.

1    Your version is incapable of returning a value of zero.
2    The type of (ptr-s) is ptrdiff_t.
3    The return type of strlen should be size_t.
peteFri Sep 26 2003, 07:02:34 AM ISTAcknowledged
7.1Technical
The XOR trick for swap macro (x ^= y ^= x ^= y) will result in side-effects and it should be avoided.
#define SWAP(x, y) (x ^= y ^= x ^= y)
Thu Apr 22 2004, 05:15:24 PM ISTAcknowledged
17.1 ProcessorsOther
486 DX+ CPU max mem is 4GB, not 4MB
Batbold DashzevegWed Jun 22 2005, 01:31:53 AM ISTAcknowledged
2510Technical
Power of 2 macro

#define ISPOWOF2( n )    ( ! ( n & ( n - 1 ) )

There is a missing paranthesis at the end ")"


The correct macro should be:

#define ISPOWOF2( n )    ( ! ( n & ( n - 1 ) ) )
Benone DorneanuFri Mar 24 2006, 05:48:56 PM ISTAcknowledged
21 8.2string functionsTechnical
   the  post increment   ++  will always increment after it 
comes out of the statement .
in while(*s1++)  ----->  after   the   string s1  reaching  NULL
it   gets  incremented  again   pointer  pointing  to   next  to 
NULL'S  address .....


while(*s1++);----->1
while(*s1++ = *s2++);----->2

first(1) will make the pointer to move next address to NULL 
as it is post increment  which will not concatenate two strings ....... out put  will be only the first string  
that   can   be   solved  by...

while(*s1) s1++;

while(*s1=*s2)s1++,s2++;
(working code............        tested)
mahanth s hiremathMon Dec 10 2007, 10:56:53 PM ISTTo be acknowledged

3791

drupal analytics
. .