twintriode
Technical User
Hi all,
I am really new to c, and I am stepping through a C manual, the "Prentice Hall, C Programming Language" book and I am having frustrating problems with alot of the early examples.
Like this simple word count program will not compile:
gives the error:
$ cc wc.c -o wc
wc.c:19:26: warning: multi-character character constant
wc.c: In function `main':
wc.c:19: error: syntax error before '|' token
wc.c: At top level:
wc.c:26: error: syntax error before string constant
wc.c:26: warning: conflicting types for built-in function `printf'wc.c:26: warning: data definition has no type or storage class
What is going on here? Could this be because the book I am using may already be outdated?
Also the following program does not seem to be doing what the book said it is supposed to:
just reads
$ ./put3
this
does
not
seem
to
be
working?
but no line count or anything.
Can anybody point out what I am doing wrong here?
I am really new to c, and I am stepping through a C manual, the "Prentice Hall, C Programming Language" book and I am having frustrating problems with alot of the early examples.
Like this simple word count program will not compile:
Code:
#include <stdio.h>
#define IN 1
#define OUT 2
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);
}
gives the error:
$ cc wc.c -o wc
wc.c:19:26: warning: multi-character character constant
wc.c: In function `main':
wc.c:19: error: syntax error before '|' token
wc.c: At top level:
wc.c:26: error: syntax error before string constant
wc.c:26: warning: conflicting types for built-in function `printf'wc.c:26: warning: data definition has no type or storage class
What is going on here? Could this be because the book I am using may already be outdated?
Also the following program does not seem to be doing what the book said it is supposed to:
Code:
#include <stdio.h>
main ( )
{
int c, nl;
nl = 0;
while ( (c = getchar ( ) ) != EOF )
if ( c == ' \n ' )
++nl;
printf ( "%d\n" , nl);
}
just reads
$ ./put3
this
does
not
seem
to
be
working?
but no line count or anything.
Can anybody point out what I am doing wrong here?