int main()
{
char a[1000] = {0};
float L;
//read a line from input
printf("Text:");
scanf("%[^\n]s", a);
float word_count = 0;
float letter_count = 0;
int sent_count = 0;
int idx = 0;
// go through the line
while (a[idx]){
// if next char is special char, then we found a sentence
while (a[idx] == '.' || a[idx] == '?' || a[idx] == '!' || a[idx] == '\n')
sent_count++;
I was expecting the above while loop to evaluate to TRUE when special characters are detected which then would increment sent_count but it doesnt work. Sent_count is always zero. I can't figure out where I am going wrong?
//skip spaces
while(a[idx] && isspace(a[idx]))
idx++;
// if next char is a letter => we found a word
if (a[idx])
word_count++;
//skip the word, increment number of letters
while (a[idx] && !isspace(a[idx])){
letter_count++;
idx++;
}
}
printf("word count = %f\nletter count = %f\n", word_count, letter_count);
L = letter_count/word_count*100;
printf("L= %.2f\n", L);
printf("# of Sentences: %d\n", sent_count);
}