TESTF.txt is the name of the file. it contains the following text :
this is the file from which the character will be searched
PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *p;
char c,d;
int c1=0;
clrscr();
p=fopen("TESTF.txt","r");
printf("Given file = ");
while((c=getc(p))!=EOF)
{
printf("%c",c);
}
rewind(p);
printf("\nEnter the character to be searched : ");
scanf("%c",&d);
while((c=getc(p))!=EOF)
{
if(c==d)
c1++;
}
printf("\nFrequency of %c = %d",d,c1);
fclose(p);
getch();
}
this is the file from which the character will be searched
PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *p;
char c,d;
int c1=0;
clrscr();
p=fopen("TESTF.txt","r");
printf("Given file = ");
while((c=getc(p))!=EOF)
{
printf("%c",c);
}
rewind(p);
printf("\nEnter the character to be searched : ");
scanf("%c",&d);
while((c=getc(p))!=EOF)
{
if(c==d)
c1++;
}
printf("\nFrequency of %c = %d",d,c1);
fclose(p);
getch();
}
No comments:
Post a Comment