First, the post's tag line is incorrect. There is no error in the code. However, some of the comments here are different views of how the same thing should be done. The problem is that everyone commenting knows C cold, but some readers do not, including the OP, and that's who this book is trying to reach. Clearly, I would not write the statement:
counter = counter + 1;
if I had already introduced the increment operator by this point in the text. There are a host of other operators and constructs I could have used (e.g., bit operators, port manipulation, the not operator), but they had not been introduced by this point in the book. The comments being made are done so out of the context in which the exercise was presented. The real problem, as I pointed out in an earlier post, is that the reader didn't read the text that is tied to the exercise, but rather simply copied the code from the book, ignoring the text telling them to add the variable named counter. Also, the point of the exercise was to show the reader the modulo operator and how it could be used with a counter to blink an LED.
It's frustrating to see someone say there's an "error" in the book when in fact the error is in their not reading the text that accompanies the code. Indeed, the OP says:
Thank you JimboZA, my program and circuit works now.
int counter = 0; is definitely missing from my book.
yet the very first line below the code the OP talks about says:
"...where the new variable, counter, is a long data type that is initialized to 0 and defined just after the data definitions for led1 and led2."
Normally, I would just sit in the background and dismiss the comment by the OP as someone who doesn't read the book carefully, but because so many experts have weighed in without understanding the context in which the exercise was presented, I felt I needed to say something.