reading from a memory location into a file

hey guys, i have a program where a certain amount of data is stored in a buffer, starting at the location pointed to by buffer.start and continuing on for buffer.length bytes. is there a function that will take care of transferring all of this information into a file for me, or will i have to do some fancy maneuvering? thanks! much appreciated-
thanks kbw- one problem i am having though. i need to output this to a file, not a device. it asks for a filedescriptor, an int. what would be great is if i could do something like this:

pFile = fopen("myfile.txt", "w");
write(pFile, buffer.start, buffer.length);
fclose();

however when i tried that, it gave me the error of pFile not being an int, understandably. how do i accomplish this? thanks!

what i have right now is something like this, but it is pretty much untested and i do not know wether it works or not...

pFile = fopen("myfile.txt", "w");
fwrite(buffer.start, buffer.length, 1, pFile);
fclose();
Last edited on
In C, there two kinds of I/O. There's the OS open/read/write/close which are unbuffered and ANSI fopen/fread/fwrite/fclose which are.

If you're using fopen, you need to use fwrite. This is the more portable way.

C environments will provide open/read ..., and they're native on Unix, but not necessarily elsewhere. For example, Windows has CreateFile/ReadFile/WriteFile/CloseHandle.
Topic archived. No new replies allowed.