L
loudking
Dear all,
I encountered a problem with fread and fwrite. If I am going to copy a
file using the same string, it will succeed
char *file_content;
struct stat buf;
FILE *fp, *new_fp;
fread(file_content, sizeof(char), buf.st_size, fp);
fwrite(file_content, sizeof(char), buf.st_size, new_fp);
If I duplicate that string, the new file will be different from the
original one.
char *bak;
fread(file_content, sizeof(char), buf.st_size, fp);
bak = strdup(file_content);
fwrite(bak, sizeof(char), buf.st_size, new_fp);
I checked the return value of both fread and fwrite, the result is
identical. I even used strcmp to compare these two strings, but they
are identical, too. so I don't know why this happens ...
BTW: fp and new_fp points to pdf files.
I encountered a problem with fread and fwrite. If I am going to copy a
file using the same string, it will succeed
char *file_content;
struct stat buf;
FILE *fp, *new_fp;
fread(file_content, sizeof(char), buf.st_size, fp);
fwrite(file_content, sizeof(char), buf.st_size, new_fp);
If I duplicate that string, the new file will be different from the
original one.
char *bak;
fread(file_content, sizeof(char), buf.st_size, fp);
bak = strdup(file_content);
fwrite(bak, sizeof(char), buf.st_size, new_fp);
I checked the return value of both fread and fwrite, the result is
identical. I even used strcmp to compare these two strings, but they
are identical, too. so I don't know why this happens ...
BTW: fp and new_fp points to pdf files.