Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- int peek()
- {
- int c;
- c = getchar();
- ungetc(c, stdin);
- return c;
- }
- void Read()
- {
- int c;
- int is_word = 1;
- int words = 0;
- int is_line = 0;
- int lines = 1;
- int is_para = 0;
- int para_no = 1;
- while((c = getchar()) != EOF)
- {
- if(!isspace(c) && is_word)
- {
- words++;
- is_word = 0;
- is_para = 1;
- }
- if(isspace(c))
- {
- is_word = 1;
- if(c == '\n' && peek() == '\n' && is_para)
- {
- printf("Paragraph %d has %d words and %d lines\n", para_no, words, lines);
- words = 0;
- lines = 0;
- is_para = 0;
- para_no++;
- }
- if(c == '\n' && peek()!='\n')
- {
- lines++;
- }
- }
- }
- }
- int main()
- {
- Read();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement