I am doing this just as an exercise coz I ran into this problem in something I was doing.
Now this might look simple enough, but its not, coz im trying to copy a 600MB file bit by bit, but it only makes a 4kb or 5kb or 9kb file depending on the buffer size I give.
Why is this happening? And how to correct it?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *from, *to;
char file1[100], file2[100], buffer[8192];
printf("Name of file to be copied: ");
gets(file1);
printf("\nName of file to be copied to: ");
gets(file2);
from = fopen(file1, "r");
to = fopen(file2, "w");
while (!feof(from))
{
fread(buffer, sizeof(char), 8192, from);
fwrite(buffer, sizeof(char), 8192, to);
}
fclose(from);
fclose(to);
return 0;
}
Now this might look simple enough, but its not, coz im trying to copy a 600MB file bit by bit, but it only makes a 4kb or 5kb or 9kb file depending on the buffer size I give.
Why is this happening? And how to correct it?