Hi Again
i got the following prog so far.
An example of how it works is as follow
Enter a paragraph with less than 99 characters.
Hi there. How are you? I guess you are fine.
the number of sentences in the paragraph are: 3
the number of words in the paragraph are: 10
But i would like to know how can i count the number of words in each sentence, instead of in the entire paragraph.
Please help
Thank You.
Code:
#include <stdio.h>
#define max_char 100
main(){
char para[max_char];
int len_sent,i,count,count_sent,illegal,sentence;
illegal = sizeof(para)-1;
printf("Please enter a paragraph with less than %d characters\n",illegal);
fflush(stdin);
fgets(para,max_char,stdin);
len_sent = strlen(para);
count_sent=0;
for (i=0; i<len_sent; i++) {
if (para[i]== '.' || para[i]=='?' || para[i]=='!')
count_sent++;
}
printf("the number of sentences are: %d\n", count_sent );
count=1;
for(i=0; i<len_sent; i++) {
if (para[i] == ' ')
count++;
}
printf("The number of words in the paragraph are %d\n",count);
}
Code tags added by Hammer