From: | Colin Wenzel |
Date: | 24 Aug 2001 at 03:28:39 |
Subject: | [amiga-c] Re: Saving and reading structs |
On 23-Aug-01, Jack York wrote:
> Hello,
> I have a declaration of something like
> struct mystruct
> {
> struct Node nn_Node;
> BOOL a;
> LONG b;
> STRPTR c;
> struct List *d;
> }mystruct;
> I allocate STRPTR c as needed so its strlen will vary with each
> instance of mystruct. I wanted to be able to save the struct to disk
> with fwite(&mystruct, sizeof(struct mystruct)... but that won't work
> because of the varying length. Any suggestions on what's the best way
> to save this?
> Jack
Your STRPTR is a (char *) - a 32 bit pointer to something,
it's NOT the actual data (string)..
If you wish to save the actual characters in the structure
you will need to define a storage space inside it so that it has
a defined maximum size for your data.... Try this...
struct mystruct
{
struct Node nn_Node;
BOOL a;
LONG b;
char c[ 16 ]; // allows up to 15 bytes + terminator in here.
struct List *d;
}
// important note, keep all BYTE sized elements in even numbers
// when declaring space within structures...
Also, please don't use non-explicitly sized types in structure definitions
otherwise you will get your arse burnt if you recompile on another
compiler that has different sized items...
eg: NO INTS !!
Regards
Colin Wenzel. 157 Brisbane Road,
Mooloolaba, Queensland, Australia. 4557.
PHONE: (07) 5444 5445
EMAIL: colstv@yahoo.com.au
EMAIL2: colinwenzel@yahoo.com
URL: http://www.hotkey.net.au/~colstv/
AMIGA: 4000T, 68060/50, 150Mb RAM,
OS 3.9, Spectrum Gfx Card + P96.
Need an Image Generator For CATV ??
http://connect.to/products
________________________________________
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Secure all your Web servers now: Get your FREE Guide and learn to: DEPLOY THE LATEST ENCRYPTION,
DELIVER TRANSPARENT PROTECTION, and More!
http://us.click.yahoo.com/VihfLB/nT7CAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/