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

Report
Posts
7
Registration date
Thursday October 3, 2013
Status
Member
Last seen
April 30, 2014
-
 indhu -
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 replies

Posts
14799
Registration date
Monday July 11, 2005
Status
Moderator
Last seen
September 1, 2020
3,164
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
Thank you

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

CCM 2864 users have said thank you to us this month

Posts
7
Registration date
Thursday October 3, 2013
Status
Member
Last seen
April 30, 2014
1
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
14799
Registration date
Monday July 11, 2005
Status
Moderator
Last seen
September 1, 2020
3,164
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 ...