Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- //calculate how many words and symbols there are in file, dont count space symbols
- int main(void)
- {
- int words, symbols = 0;//words count, symbols count
- char c,prev; //current char, previous char
- words = 0;
- bool inword = 0; //
- while((c = getchar()) != EOF)
- {
- if(inword)
- {
- if(isspace(c))//just got out of word
- inword = 0;
- else //keep being in word
- symbols++;
- }
- else
- {
- if(!isspace(c))//just got into word
- {
- words++;
- inword =1;
- symbols++;
- }
- //keep being out of word, nothing to be done,no operators
- }
- prev = c;
- }
- printf("words %d, symbols %d\n",words,symbols);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement