I have a function that writes random numbers into a file while reading another file.
void writeFile() {
    FILE* file = fopen(source, "r");
    FILE* file2 = fopen(target, "w");
    srand (time(NULL));
    while (!feof(file)) {
        fgetc(file);
        fputc(0 + ( rand() % ( 50 - 0 + 1 ) ), file2);
    }
    fclose(file);
    fclose(file2);
}
The two files should have the same size. What happens is that the second file has more 1byte at the end compared with the first file. How can I avoid this?
 
     
     
    