Go Back   AnandTech Forums > Software > Programming

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2014
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 02-09-2013, 12:30 PM   #1
Onceler
Golden Member
 
Onceler's Avatar
 
Join Date: Feb 2008
Posts: 1,247
Default I can not figure this out

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[i]=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[i]);
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 by Onceler; 02-09-2013 at 01:22 PM.
Onceler is offline   Reply With Quote
Old 02-09-2013, 01:07 PM   #2
Crusty
Lifer
 
Crusty's Avatar
 
Join Date: Sep 2001
Location: ATX
Posts: 12,317
Default

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.
__________________
Consequences will never be the same!

/^1?$|^(11+?)\1+$/
Crusty is offline   Reply With Quote
Old 02-09-2013, 02:29 PM   #3
Onceler
Golden Member
 
Onceler's Avatar
 
Join Date: Feb 2008
Posts: 1,247
Default

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?
Onceler is offline   Reply With Quote
Old 02-09-2013, 02:40 PM   #4
sandorski
No Lifer
 
sandorski's Avatar
 
Join Date: Oct 1999
Location: coquitlam, bc
Posts: 57,379
Default

'=' before "EOF" ?
__________________

FX 8320@4ghz||Zalman LQ310||AsusM5A99X EVO R2
||XFX 5870 1gb||16gb Corsair Vengeance DDR3||Seasonic M12 II 500watts||Zalman Z9 Plus||Asus MS238H

Science inspires us towards a better tomorrow, Fundamentalism wants us to die.
sandorski is offline   Reply With Quote
Old 02-09-2013, 05:16 PM   #5
EagleKeeper
Discussion Club Moderator
Elite Member
 
EagleKeeper's Avatar
 
Join Date: Oct 2000
Location: Bumps west of Denver
Posts: 42,600
Default

Quote:
Originally Posted by sandorski View Post
'=' 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
Reading and/or typing
__________________
F15 Air Superiority Fighter - Never has one been lost in aerial combat (104 kills)

Last edited by EagleKeeper; 02-09-2013 at 05:19 PM.
EagleKeeper is offline   Reply With Quote
Old 02-10-2013, 03:08 AM   #6
Aluvus
Platinum Member
 
Aluvus's Avatar
 
Join Date: Apr 2006
Posts: 2,894
Default

Quote:
Originally Posted by Onceler View Post
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.
__________________
Map of Semiconductor Fabs | TLD Locator
Aluvus is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:54 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.