How to count sentences in a paragraph..." using c language [Solved/Closed]

Posts
7
Registration date
Thursday October 3, 2013
Last seen
April 30, 2014
- - Latest reply:  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();
}
See more 

3 replies

Best answer
Posts
14289
Registration date
Monday July 11, 2005
Status
Moderator
Last seen
December 14, 2018
4
Thank you
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 ...

Say "Thank you" 4

A few words of thanks would be greatly appreciated. Add comment

CCM has helped 2750 users this month

Posts
7
Registration date
Thursday October 3, 2013
Last seen
April 30, 2014
1
Thank you
thank you so much

its my pleasure to receive your comments

it finally work....

#include<stdio.h>
int main() {
char paragraph[1000];
int nbChar=0, nbSentences;
int i;


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


nbChar = strlen(paragraph);


nbSentences = 0;
for (i=0; i<nbChar; i++){
if (paragraph[i]=='.'){
nbSentences++;
}
}


printf("\n\nTotal sentences: %d", nbSentences);

getch();
return 0;
}

thank you once again for your help..........
its very help full for me thank u bro
Posts
14289
Registration date
Monday July 11, 2005
Status
Moderator
Last seen
December 14, 2018
0
Thank you
You're welcome. I'm glad it is working for you ;)

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