Hello people i've done a program that replace a letter for another one using cmd. But i'm having issues trying to replace a whole word. i'm new using files, so i've tried to use fgets and fputs, but i had no results. :/
This is my code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//Function's prototypes
void atributos(int argc,char *argv[]);
void SustChar(char *argv[]);
//MAIN
int main(int argc, char *argv[]){
FILE *ptrf;
ptrf=fopen(argv[1],"r");
if(ptrf==NULL){
printf("No se pudo abrir el archivo\n");
exit(1);
}
else{
fclose(ptrf);
atributos(argc,argv);
}
return 0;
}
//attributes
void atributos(int argc,char *argv[]){
if(strcmp(argv[2],"S")==0)
SustChar(argv);
}
//Replace words
void SustChar(char *argv[]){
char c[80];
FILE *ptrf;
ptrf=fopen(argv[1],"r");
FILE *ptrs;
ptrs=fopen(argv[5],"w");
while(!feof(ptrf)){
c=fgetc(ptrf);
if(c==*argv[3])
fputc(*argv[4],ptrs);
else
fputc(c,ptrs);
}
fclose(ptrs);
fclose(ptrf);
}
The sintaxis i'm using on cmd is: .exeName origin.txt S oldword newword destiny.txt