I have to make a program that takes the file that is firs command line argument and whenever it finds a char in that file that is same as the second command line argument it switches it with char that is third command line argument
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
FILE *cit;
char s[100];
int i;
cit=fopen(argv[1],"r");
if (cit==NULL)
return 1;
fgets(s,100,cit);
int d=strlen(s);
for(i=0;i<d;i++)
{
if(s[i]==argv[2])
s[i]=argv[3];
}
s[i]=0;
fclose(cit);
cit=fopen(argv[1],"w");
if(cit==NULL)return 1;
fputs(s,cit);
fclose(cit);
return 0;
}
When i run it using command prompt it shows no errors or something, yet nothing changes in file, probably because string remained the same after my for loop, but i can't tell what's wrong.