Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 100
- #define IN 1
- #define OUT 2
- int word_count(char str[]);
- int main()
- {
- char str[SIZE];
- gets(str);
- printf("%d\n", word_count(str));
- return 0;
- }
- int word_count(char str[])
- {
- int i, state = OUT, count = 0;
- for(i = 0; str[i] != '\0'; i++)
- {
- if((str[i] >= 'a' && str[i] <= 'z' ) || (str[i] >= 'A' && str[i] <= 'Z'))
- {
- if(state == OUT)
- {
- state = IN;
- count++;
- }
- }
- else
- state = OUT;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement