Write a c program to count the number of character ,number of lines from a text file and display the result
#include<stdio.h>
#include<conio.h>
void main()
{
int noc=0,now=0,nol=0;
FILE *fw,*fr;
char fname[20],ch;
clrscr();
printf("\n enter the source file name");
gets(fname);
fr=fopen(fname,"r");
if(fr==NULL)
{
printf("\n error \n");
exit(0);
}
ch=fgetc(fr);
while(ch!=EOF)
{
noc++;
if(ch==' ');
now++;
if(ch=='\n')
{
nol++;
now++;
}
ch=fgetc(fr);
}
fclose(fr);
printf("\n total no of character=%d",noc);
printf("\n total no of words=%d",now);
printf("\n total no of lines=%d",nol);
getch();
}
#include<conio.h>
void main()
{
int noc=0,now=0,nol=0;
FILE *fw,*fr;
char fname[20],ch;
clrscr();
printf("\n enter the source file name");
gets(fname);
fr=fopen(fname,"r");
if(fr==NULL)
{
printf("\n error \n");
exit(0);
}
ch=fgetc(fr);
while(ch!=EOF)
{
noc++;
if(ch==' ');
now++;
if(ch=='\n')
{
nol++;
now++;
}
ch=fgetc(fr);
}
fclose(fr);
printf("\n total no of character=%d",noc);
printf("\n total no of words=%d",now);
printf("\n total no of lines=%d",nol);
getch();
}
very nice program...quite helpful.
ReplyDeletebut plz change ur profile pic
not cool
Thank you for the above Program...
ReplyDeleteThank you for the above program.
ReplyDeletewww.edugate.info
ok verry well
ReplyDeleteTHANKSYOU
ReplyDeleteERROR l6: unused 'fw' file pointer.
ReplyDeleteERROR l6: unused 'fw' file pointer.
ReplyDeletethanks :)
ReplyDeletethanks :)
ReplyDeletethanks :)
ReplyDeleteConfused with word count
ReplyDeleteConfused with word count
ReplyDelete