I'm completely new to C and have this example from The C Programming Language book:
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* count line and words and characters in input */
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 code compiles fine in the terminal with: gcc -o count count.c When I run it with: ./count it let's me test it, gives me a new line to type in the input. I type in, hit the Return and it gives me another blank line for my text input, not outputting anything. What is it that I do wrong? I was doing some other examples with input and I was receiving an output, but none of the code that I use from this book works for me now. Many thanks.