How to count sentences in a paragraph..." using c language

Solved/Closed
gealon2024 Posts 7 Registration date Thursday October 3, 2013 Status Member Last seen April 30, 2014 - Oct 3, 2013 at 10:11 PM
 indhu - Jan 10, 2016 at 08:47 AM
Hi. everyone ;

can anybody help me or explain to me how to make a program using C LANGUAGE "how to count sentences in a paragraph..."
#include <stdio.h>
main(){
char x[1000];
int i,count=0;
char m;
/* I dont know whats wrong with this one */

clrscr();

printf("Enter your a paragraph\n\n\t: ");
gets(x);

for(i=0;m!='.';i++){
m=getchar();
x[i]=m;
}

count='.';

for(i=0;count!='.';i++){
if(count=='.'){
count++;


}
}
printf("\n\nTotal sentences: %d",count+1);
getch();
}

3 responses

BunoCS Posts 15495 Registration date Monday July 11, 2005 Status Moderator Last seen October 23, 2024 1,533
Oct 4, 2013 at 03:41 AM
Hello,
Grammatically speaking, a sentence is terminated by a dot. If you want to count the number of sentences, you just have to count the number of dots

Here is a piece of code. Not tested but the idea is here

int main()
{
char paragraph[1000];
int nbChar, nbSentences;

// display prompt and get paragraph
clrscr();
printf("Enter your a paragraph\n\n\t: ");
gets(paragraph);

// get number of characters
nbChar = strlen(paragraph);

// read paragraph and count dot character
nbSentences = 0;
for (int i=0; i<nbChar; i++)
{
if (paragraph[i]=='.')
{
nbSentences++;
}
}

// display result
printf("\n\nTotal sentences: %d", nbSentences);
getch();
return 0;
}

Note: I've renamed your variables to make sense

@+
Buno, Modo CS-CCM
The urgent is done, the impossible is underway. For miracles, envisage a time ...
4