Advertisement
STANAANDREY

wc impl

Nov 5th, 2022
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main() {
  5.   int lines = 0, wordCnt = 0, chCnt = 0;
  6.   char ch, prev = ' ';
  7.   while ((ch = getchar()) != EOF) {
  8.     if (ch == '\n') {
  9.       lines++;
  10.     }
  11.     if (isspace(ch) && !isspace(prev)) {
  12.       wordCnt++;
  13.     }
  14.     prev = ch;
  15.     chCnt++;
  16.   }
  17.   printf("%d %d %d\n", lines, wordCnt, chCnt);
  18.   return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement