Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int word_count(char mystr1[]);
- int main ()
- {
- char mystr1[]= "How are you today?";
- printf("This is the string...\n");
- printf("%s\n\n", mystr1);
- printf("Number of words is: %d\n", word_count(mystr1));
- system("PAUSE");
- return 0;
- }
- int word_count(char mystr1[])
- {
- int i=0;
- int counter=0;
- while(mystr1[i]!= '\0')
- {
- if (mystr1[i]==' ')
- {
- if ((mystr1[i+1] >= 'A' && mystr1[i+1] <= 'Z')
- || (mystr1[i+1] >= 'a' && mystr1[i+1] <= 'z'))
- {
- counter++;
- }
- }
- i++;
- }
- if ((mystr1[0] >= 'A' && mystr1[0] <= 'Z')
- || (mystr1[0] >= 'a' && mystr1[0] <= 'z'))
- counter++;
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement