I have some code here:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main (int argc, char *argv[])
{
char c;
FILE *fp;
fp = fopen(argv[1], "r");
if (fp == NULL)
{
printf ("Errore nell'apertura del file %s\n\n", argv[1]);
exit(EXIT_FAILURE);
}
while ( (c = getc(fp)) != EOF)
{
if (strcmp(c,argv[2]) == 0)
{
c = argv[3];
}
putchar(c);
}
return 0;
}
First question: i have to replace some characters in argv[2] on my file (argv[1]) with some other characters on argv[3]... i know that c = argv[3]
is a BIG wrong horror thing but... how can i replace my "c" with the character i wrote in argv[3]??
EX: out.exe file.txt a b
------ -------- - -
program file 1 2
name name letters
Second question: if in argv[2] i have 2 char, the first is the character to replace and the second is the one with which i have to replace, how can i write it??
EX: out.exe file.txt ab
------ -------- --
program file 1/2
name name letters (both on argv[2])