Opening a file-handle in a program is a little different than opening a document in a Word Processor. It's more like opening a book. To read or write you have to use your eyes (consuming the data) or a pencil (producing the data).
Since you have the files open, you need to read data from the first file and write it to the second file. Something like:
size_t nread;
do {
nread = fread(msg, 1, 1024, old_file);
fwrite(msg, 1, nread, new_file);
} while(nread != 0);
Or
int nread;
do {
nread = fgets(msg, 1023, old_file);
fputs(msg, new_file);
} while (nread > 0);
Or even just a char at a time.
int c;
while ( (c=fgetc(old_file)) != EOF) {
fputc(c, new_file);
}
Also, you're not prepending the "./" to the second file. Not sure if that's important, but you did it to the first file.
Also, you should use fopen
on new_file. freopen
isn't wrong per se, but it's weird and will confuse others (including me).
The freopen() function opens the file whose name is the string pointed to by path and associates the stream pointed to by stream with it. The original stream (if it exists) is closed. The mode argument is used just as in the fopen() function. src:manpage
So, it will open the stream as you wish, but it destroys stdout when it does this. So your program cannot do normal output anymore. This may not be important, but then there doesn't appear to be any real advantage either.