SHARE
TWEET

Untitled

a guest Oct 21st, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int peek()
  5. {
  6.     int c;
  7.     c = getchar();
  8.     ungetc(c, stdin);
  9.     return c;
  10. }
  11.  
  12. void Read()
  13. {
  14.     int c;
  15.     int is_word = 1;
  16.     int words = 0;
  17.     int is_line = 0;
  18.     int lines = 1;
  19.     int is_para = 0;
  20.     int para_no = 1;
  21.     while((c = getchar()) != EOF)
  22.     {
  23.         if(!isspace(c) && is_word)
  24.         {
  25.             words++;
  26.             is_word = 0;
  27.             is_para = 1;
  28.         }
  29.  
  30.         if(isspace(c))
  31.         {
  32.             is_word = 1;
  33.             if(c == '\n' && peek() == '\n' && is_para)
  34.             {
  35.                 printf("Paragraph %d has %d words and %d lines\n", para_no, words, lines);
  36.                 words = 0;
  37.                 lines = 0;
  38.                 is_para = 0;
  39.                 para_no++;
  40.             }
  41.             if(c == '\n' && peek()!='\n')
  42.            {
  43.                lines++;
  44.            }
  45.         }
  46.     }
  47. }
  48.  
  49. int main()
  50. {
  51.     Read();
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top