I'm writing a program for class that reads from a file and then replaces a word with another word and writes that to a file. Right now I'm just doing the basic which is reading from one file and then writing to another....Which I thought would be pretty simple. I am familiar with C++ but with this I am confused on how to exactly do it.
The problem I'm having is that it will only write the last line and for some reason doesnt read the first lines.
(i'm using it in linux so...it would have to be like: ./replace string1 string2 FILENAME)
#define MAX 512
int main(int argc, char *argv)
FILE *file, *file2;
if (argc != 4)
printf("You must enter: ./replace old-string new-string file-name\n");
file = fopen(argv, "r");
file2 = fopen("temp", "w");
while (fgets(line,sizeof(line),file) != NULL);
/*Write the line */
Thanks for any help you can give...or any direction you can point me in,