#include <stdio.h>
#define MAXBUF 100
int main()
{
char *in = "Sample.txt";
char *out = "outFile.txt";
char buf[MAXBUF];
FILE *rfs, *wfs;
rfs = fopen(in, "r");
/* error checking required */
wfs = fopen(out, "w");
/* error checking required */
while(fgets(buf, MAXBUF, rfs))
{
fputs(buf, wfs);
}
fclose(rfs);
fclose(wfs);
return 0;
}
I found the solution on Stackoverflow. You can see the solution in this post.Labels: debugging in C, fgets, file copying in C, fputs