Advertisement
iamthehxc

Untitled

Jul 22nd, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. int word_count(char mystr1[]);
  3. int main ()
  4. {
  5.     char mystr1[]= "How are you today?";
  6.    
  7.     printf("This is the string...\n");
  8.     printf("%s\n\n", mystr1);
  9.    
  10.     printf("Number of words is: %d\n", word_count(mystr1));
  11.      
  12.     system("PAUSE");
  13.     return 0;
  14. }
  15.  
  16. int word_count(char mystr1[])
  17. {
  18.     int i=0;
  19.     int counter=0;
  20.      
  21.     while(mystr1[i]!= '\0')
  22.       {
  23.         if (mystr1[i]==' ')
  24.          {
  25.            if ((mystr1[i+1] >= 'A' && mystr1[i+1] <= 'Z')
  26.                || (mystr1[i+1] >= 'a' && mystr1[i+1] <= 'z'))
  27.                  {
  28.                    counter++;
  29.                  
  30.                  }
  31.            
  32.          }
  33.          i++;
  34.       }
  35.     if ((mystr1[0] >= 'A' && mystr1[0] <= 'Z')
  36.                || (mystr1[0] >= 'a' && mystr1[0] <= 'z'))
  37.                   counter++;
  38.        
  39.     return counter;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement