- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Store C struct in binary file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2005 07:59 AM
тАО05-21-2005 07:59 AM
I'm looking for a standart way to store a C structure in a binary file. I never used this kind of thing and after some googling I still did not find the answer.
Actually, I'm looking for some really low-level storage mechanism in binary files. I know there some nice programs like berkeley db, but it's not good enough because they are GPL or commercial. I'm not sure that the program I'm writing gonna be GPL and also I don't plan to pay any money.
Thanx.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2005 03:50 PM
тАО05-21-2005 03:50 PM
Solution- Tags:
- write
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2005 07:35 AM
тАО05-23-2005 07:35 AM
Re: Store C struct in binary file
of the POSIX read(), write(), etc.) you can
also use fread() and fwrite(). If you want
to be platform-independent you should
probably check out XDR too (man xdr).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2005 08:22 AM
тАО05-23-2005 08:22 AM
Re: Store C struct in binary file
Alex.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 12:17 AM
тАО05-24-2005 12:17 AM
Re: Store C struct in binary file
Alex.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 01:07 AM
тАО05-24-2005 01:07 AM
Re: Store C struct in binary file
Let's say your memory structure "mystruct" is already defined - and your file "MYFILE" is already opened .
fwrite (&mystruct, (size_t)sizeof(mystruct),1,MYFILE);
to get it back:
fread (&mystruct, (size_t)sizeof(mystruct),1,MYFILE);
If you've created an array of these structures - you can save them all by setting your pointer to the first one - and passing the number of elements in your "array" as the third argument - then they'll all be passed.
Be aware that due to padding in some compilers, you could do this one compiler, and the padding could be off if you read back the same data file in another. Doesn't always happen, it's just that you should check b/w compilers if that is necessary.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 01:12 AM
тАО05-24-2005 01:12 AM