I've learned to write bytes from a file by reading the entire file into a character array and then writing them out to another file using fwrite. Of course, my teacher told me this is both wasteful and a file might not fit into memory, so I should use another method. What I want to do is write the exact copy of a file into my own file. How can I do this the better way? Thanks
RexxX
0
Light Poster
Recommended Answers
Jump to Postuse fgets to read the source file one line at a time. this will take a small character array of some arbitrary length. say 80 or 120 characters. you could do it a lot smaller, but i don't see any reason why you would want to..
use fprintf to …
Jump to PostTry looking at the macro BUFSIZ.
I found this about BUFSIZ
Macro: int BUFSIZ
The value of this macro is an integer constant expression that is good to use for the size argument to setvbuf. This value is guaranteed to be at least 256.The value of BUFSIZ is …
Jump to Postno. not at all.
it doesnt get any more convenient than the example i handed you.
Jump to Postit doesnt work because file pointers and char pointers are two different things.
short answer: if they weren't different, they wouldn't have different names.
long answer: a char pointer is just a memory address that points to a location in memory of a group of characters. a file …
Jump to PostHow would it handle a file pointer different from a char pointer? I can't use fgets because of binary files though, but fread and maybe 80 bytes will work fine.
EDIT - it has to be an exact number of bytes output...*sigh* so 80 fixed won't work.
okay, you're getting …
All 17 Replies
jephthah
1,888
Posting Maven
gerard4143
371
Nearly a Posting Maven
RexxX
0
Light Poster
jephthah
1,888
Posting Maven
RexxX
0
Light Poster
jephthah
1,888
Posting Maven
jephthah
1,888
Posting Maven
RexxX
0
Light Poster
gerard4143
371
Nearly a Posting Maven
jephthah
commented:
we don't do people's homework.
-1
jephthah
1,888
Posting Maven
jephthah
1,888
Posting Maven
RexxX
0
Light Poster
jephthah
1,888
Posting Maven
RexxX
0
Light Poster
jephthah
1,888
Posting Maven
gerard4143
371
Nearly a Posting Maven
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.