tonitop
asked on
Writin/Reading struct from/into binary file? (DOS)
How do I read and write struct into file? Here's simple struct:
struct names
{
char name[20];
int age;
};
struct names list[20];
I know I can use fputs() and write the whole struct into ascii file in one for-loop, but now I would like to know how I can use binary files. Is there similar ways to do it in a loop? Example would be nice.
I'm using Turbo C++ 3.0 and DOS (yes, it's still alive :)
struct names
{
char name[20];
int age;
};
struct names list[20];
I know I can use fputs() and write the whole struct into ascii file in one for-loop, but now I would like to know how I can use binary files. Is there similar ways to do it in a loop? Example would be nice.
I'm using Turbo C++ 3.0 and DOS (yes, it's still alive :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You have to be careful with the file position though. fseek() and ftell() are your friends.