Hallo, I am trying to replace a character in a file with another. To get access to teh characters in the file I used the fgetc function. I can print out the contents of file on the screen but the problem is I can't get to replace the character. Any help is appreciated. Here is my attempt.
Code:#include <stdio.h> int main() { char c; char string[40]; FILE *file; int i=0; file = fopen("example.txt", "r"); //Here I am opening the file and the file opens successfully if(file==0) { perror("fopen"); } //Here is now the loop, seems there is a problem //here though I can't figure out exactly while ((c = fgetc(file))!=EOF) { for (i; i<sizeof(c); i++) string[i] = c; if (string[i]=='a')//I want to replace with the character //b everywhere a appears and then printout the result {string[i]='b';} printf("%c",c);}//Here is my attempt to print out but the characters // are not replaced }