I/O Routines..question?
My Code:
//prtfile is the file handle.
fwrite (&struct->structvalue,sizeof(struct->structvalue), sizeof(struct->structvalue),ptrFile);
first question...Is this the right way to save structures data to files..
second question... if it is that is the right way , how do i know how much to read from the file when i have to load the data again to the struct.
:confused:
[406 byte] By [
HPK] at [2007-11-17 22:38:49]

# 1 Re: I/O Routines..question?
Well...your third parameter should be 1 (you're only saving 1 structure), but otherwise it looks OK. When you read it back, use the "fread" equivalent to your "fwrite", and the correct number of bytes will be automatically read.
If you're trying to save an array of structures (or anything else), I recommend you first write the number of structures to the file as a binary number, followed by the structures themselves.
I suspect this is a school project - good luck!
TSYS at 2007-11-10 8:41:44 >
