Originally Posted by
Salem
> Or what does readParagraph mean and use for in counting the words in each paragraph?
It really stems from your definition of a text file.
A file is composed of one or more paragraphs.
A paragraph is one or more sentences.
A sentence is one or more words.
A word is one or more characters.
I mean that paragraphs are counted when pressing enter. And after finding total no of paragraphs, I have tried to use strtok after reading its use[URL="http://http://www.cplusplus.com/reference/clibrary/cstring/strtok.html"]
But now, there is some problem here. Would someone tell me how to solve it? I would be thankful for your help.
Code:
ch=fgetc(infp);
while(ch!=EOF)
{
if(ch=='\n')
count_p++;
ch=fgetc(infp);
}
printf("Total number of paragraph(s):%d\n",count_p+1);
do{
t1=strtok(all_word,'\n');
count_pw[20]=0;
while(fgets(all_word,300,infp)!=NULL)
{
for(i=0;i<count_p+1;i++)
{count_pw[i]++;
printf("Total number of words in paragraph %d: %d\n",count_p+1,count_pw[count_p+1]);
t1=strtok(NULL,'\n');
}
}while(fgets(all_word,300,infp)!=EOF);