Re: Count total no. of characters,words & sentences in a text file
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Tue, 24 Apr 2007 10:09:42 +1200
Umesh wrote:
//Sorry my teachers. I've included file opening check in this program.
#include<stdio.h>
int main(void)
{
long int ch,c,num=0,num1=0,num2=0,num3=0;
Use meaningful names and declare them in the scope where they are used.
FILE *f;
f=fopen("c:/1.txt","r");
Whitespace is free, use it. This will only work on a system where
"c:/1.txt" is a valid filename and where "c:/1.txt" exists...
if (f!=NULL)
{
while((ch=getc(f))!=EOF && (ch=getc(f))!=EOF)
Why are you doing this?
{
if(ch==' ') ++num;
if(ch=='.') ++num1;
if(ch<=256) ++num2;
if(ch=='.' && c!=' ') ++num3; // '.' followed by '.' denotes end of a
sentence.
If you are going to add comments, make sure they make sense and agree
with the code.
--
Ian Collins.
.
- References:
- Prev by Date: Re: Deleting a File
- Next by Date: Re: C Object System
- Previous by thread: Re: Count total no. of characters,words & sentences in a text file
- Next by thread: Re: Count total no. of characters,words & sentences in a text file
- Index(es):
Relevant Pages
|