I can not figure this out

Onceler

Golden Member
Feb 28, 2008
1,264
0
71
I am trying to learn C from the second edition of The C Programming Language and on two programs they won't compile, I am using GCC and code::blocks
the first is 1.5.4 Word Counting
#include <stdio.h>
#define IN 1
#define OUT 0
main ()
{
int c,nl,nw,nc,state;
state = OUT;
nl=nw=nc=0;
while ((c=getchar())!=EOF){
++nc;
if (c== '\n')
++nl;
if (c ==' ':: c=='\n'::c=='\t')
state=OUT;
else if(state==OUT){
state=IN;
++nw;
}
}
printf("%d %d %d \n",nl,nw,nc);
}
the compiler tells me that there is an expected ')' before ':' token on line 13
also on 1.6 Arrays
#include<stdio.h>
main()
{
int c, i, nwhite, nother;
int ndigit[10];
nwhite=nother=0;
for (i=0;i<10;++i)
ndigit=0;
while((c=getchar())!EOF)
if(c>='0'&&c<='9')
++ndigit[c-'0'];
else if(c==' ':: c=='\n'::c=='\t')
++nwhite;
else ++nother;
printf ("digits =");
for (i=0; i<10;++i)
printf(" %d",ndigit);
printf(", white space =%d, other=%d\n",nwhite,nother);

}
On line 9 expected')' before '!' token then the same error as before on line 12.
Am I doing something wrong or is my compiler at fault? I have tried retyping these from blank files and still do not get results.
I am very frustrated and even though the code makes sense to me I am not exactly inspired with confidence from these errors.
Code::Blocks is version 12.11
Ia it CB or my compiler and if it is the compiler what can I do about it?
Thanks
 
Last edited:

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Well the '::' operator does not exist in the C language, which is what you are using in your if statements in both programs. Did you retype these examples from a book? I'm guessing you meant to use the || operator, which is the logical OR operator.
 

Onceler

Golden Member
Feb 28, 2008
1,264
0
71
Thank you.
I tried it with || and the first one works I don't know why but the book looks like::
any thoughts on the second prog?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,591
5
0
'=' before "EOF" ?

while ((c=getchar()) != EOF)

As indicated above

[quote\] Ia it CB or my compiler and if it is the compiler what can I do about it?[/quote]

Programmer error :p
Reading and/or typing
 
Last edited:

Aluvus

Platinum Member
Apr 27, 2006
2,913
1
0
Thank you.
I tried it with || and the first one works I don't know why but the book looks like::
any thoughts on the second prog?

The "pipe" symbol is sometimes rendered as a vertical line with a gap in the middle, particularly on keyboards (including mine). Printing it that way in a book, especially one that would use it so frequently, seems like a poor choice.