Vote count:
0
Write a program to count the number of times a character appears in the File. (Case insensitive... 'a' and 'A' are considered to be the same)
`
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
FILE *fp1;
char ch,f[100],c,d;
int ct=0;
printf("Enter the file name\n");
scanf("%s",f);
fp1=fopen(f,"r");
printf("Enter character:");
scanf(" %c",&c);
do
{
printf("%c",ch);
ch=fgetc(fp1);
d=toupper(ch);
printf("%c",d);
if(c==d)
++ct;
}while(ch!=EOF);
fclose(fp1);
printf("\n");
printf("%d",ct);
return 0;
}`
This the program i have written but the output i'm getting it is..
[ a.txt contains the string- aaa ]
Now when running the program this is what i get
Enter the file name
a.txt
Enter character:a
aAaAa
0
asked 55 secs ago
Write a program to count the number of times a character appears in the File. (Case insensitive... 'a' and 'A' are considered to be the same)
hello there,
RépondreSupprimerfor running the above program, we need to have a file in local disk for eg: a.txt right?? or else what v have to do for running the file?? pls help :)
hello there,
RépondreSupprimerfor running the above program, we need to have a file in local disk for eg: a.txt right?? or else what v have to do for running the file?? pls help :)