I am trying to copy contents of one file to another character by character using a loop.
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE * fp1=fopen("file1.txt","r");
FILE * fp2=fopen("file2.txt","w");
char c;
while(!feof(fp1)){
c=fgetc(fp1);
fputc(c,fp2);
}
return 0;
}
Consider that we have hello
in the file1, after running the code the content present in file2 is hello�
.
Why I am getting this extra character (�
)? Is there anything wrong with my piece of code?