I want to find a way to replace the word that was found the same with the user input. For instance, the user inputs "er" and then these words come up:
What I want to do is replace the "er" on all of these words with again a user input. for example , the user then writes "el" instead of "er". When this happens, the original file will not change but another file will be created that will save all the changes made. Does anyone have an idea?
#include <stdlib.h>
#include <string.h>
#include<conio.h>
#define MAX 1024
int main(int argc, char* argv[]) {
FILE* myFile = fopen("C:\\Users\\doom\\Desktop\\txtfiles\\singlewords.txt", "r+");
FILE* myFile1 = fopen("C:\\Users\\doom\\Desktop\\txtfiles\\sentences.txt", "r+");
FILE* tempFile = fopen("C:\\Users\\doom\\Desktop\\txtfiles\\singlewordstemp.txt", "w");
char inputWord[MAX];
char inputRepl[MAX];
char lineBuffer[MAX];
char all_lines[MAX];
//char buffer[MAX + 2];
//char* buff_ptr, * find_ptr;
//size_t find_len = strlen(lineBuffer);
if (myFile == NULL)
{
printf("File Does Not Exist \n");
return 1;
}
strcat(all_lines, lineBuffer);
printf("Enter the word \n");
fgets(inputWord, MAX, stdin);
//printf("\nEnter String to replace:");
//scanf("%s", inputRepl);
while (!feof(myFile))
{
char lineBuffer[1024];
fscanf(myFile, "%1024[^\n]\n", lineBuffer);
//printf("%s\n", lineBuffer);
while (fgets(lineBuffer, MAX, myFile)) {
if (strstr( lineBuffer, inputWord))
puts(lineBuffer);
}
}
}