Here's the word counting program. This is the one in K&R book. It can certainly be the best book for C beginners. I recommend that book to you.
Code:
#include <stdio.h>
#define IN 1
#define OUT 0
main()
{
in 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);
}
I am supposing you know all of these grammars and syntax.
This is a very basic word counting program.
nw is a value of words. So, the value printed in the middle should show how many words you typed.
And you should know about EOF signals.
Mostly, when it comes to "counting" something, it usually comes with an increment operator. ++variable <--- like this.