Guest User

Untitled

a guest
May 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main(void)
  5. {
  6.     FILE * file;
  7.     int c;
  8.     int iw = 0;
  9.     int nl = 0, nw=0, nb=0;
  10.     file=fopen("mobydick.txt", "r");
  11.     while (1)
  12.     {
  13.         if (feof(stdin) || ferror(stdin))
  14.             break;
  15.            
  16.         c=getc(file);
  17.        
  18.         if (c < 0)
  19.             break;
  20.         nb++;
  21.        
  22.         if ( c == '\n')
  23.             nl++;
  24.        
  25.         if (isspace(c))
  26.             iw = 0;
  27.         else if ( iw == 0)
  28.         {
  29.             nw++;
  30.             iw=1;
  31.         }
  32.        
  33.     }
  34. printf("%d %d %d\n", nl,nw,nb);
  35. }
Add Comment
Please, Sign In to add comment