C File =>
/* Write a C program to accept file name and character as command line arguments and count number of occurrences of given character in the file. */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char *argv[])
{
char ch,cnt=0;
char c=argv[2];
FILE *fp;
fp=fopen(argv[1],"r");
while((ch=fgetc(fp))!=EOF)
{
if(ch==c)
cnt++;
}
printf("\n Count of %c = %d",argv[2],cnt);
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.