source file name: countfile.C
#include<stdio.h>
int main(int a, char *b[])
{
char ch;
int chr=0;
int sp=0;
int ln=0;
int tb=0;
FILE *fp;
fp=fopen("welcome.txt","r");
//clrscr();
printf("file handling program\n ");
while((ch=fgetc(fp))!=EOF)
{
chr++;
if(ch=='\n')
ln++;
if(ch=='\t' )
tb++;
if(ch==' ')
sp++;
}
chr=chr-(sp+tb+ln);
printf(" tabs= %d ",tb);
printf(" spaces= %d ",sp);
printf(" lines= %d ",ln);
printf(" chars= %d ",chr);
//getch();
return 0;
}
Note:
create welcome.txt file with below contains
wel come to DBJ College Chiplun
also cs dept.
by fy students
C Programming
Output:
File
handling program
Tabs=3 spaces=8
lines=4 chars=68
0 Comments
Post a Comment