Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
strdup + fread = fail?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="loudking, post: 2864339"] 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. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
strdup + fread = fail?
Top