Can someone assist me in writing a function that counts words that the user inputs?
Can someone assist me in writing a function that counts words that the user inputs?
Use easier terms I'm a newbie.
I have the StrSpn() function written. But I need this to not only count but output the words individually. I'm still working. Any hints would be appreciated.
I cant use anything but stdio.h
This is only part of the assignment but here what i have for this part:
Code:#include <stdio.h> #define IN 1 #define OUT 0 main() { int c; int nw; int state; state = OUT; nw = 0; while((c == getchar()) != EOF) { if(c == ' ' || c == '\n' || c == '\t') state = OUT; else if(state == OUT) { state = IN; ++nw; } } printf("%d", nw); }
>>while((c == getchar()) != EOF)
This is wrong, it should be
>>while((c = getchar()) != EOF)
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Ok.