Ladies_Man

1_14 Wordcount

Dec 15th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int wcount (char *s)
  6. {
  7.     int i = 0, n = 0;
  8.     while (i != strlen(s)){
  9.         if (((s[i] != ' ') && (s[i] != 9))  && ((s[i+1] == ' ') || (s[i+1] == 13) || (s[i+1] == 9) || (s[i+1] == 0)))  n++;
  10.         i++;
  11.     }
  12.     //printf("%d  %d  %d", s[i-1], s[i], s[i+1]);
  13.     return n;
  14. }
  15.  
  16. int main()
  17. {
  18.     char s[100];
  19.     gets(s);
  20.     printf ("%d", wcount (s));
  21.    //printf("%c , %d", s[4], s[4]);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment