From: | Jack York |
Date: | 24 Aug 2001 at 12:58:44 |
Subject: | [amiga-c] Re: Saving and reading structs |
Hello Colin
On 24-Aug-01, Colin Wenzel wrote:
> 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...
Thanks for the suggestion Colin. I normally use the method you describe but in
this instance I'm using char * and allocating as needed since the length of the
strings being stored vary significantly and I'm not always sure of what the
maximum size will be (like a path to a file).
> 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 !!
I don't. Only those defined in exec/types.h.
Jack
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Do you need to encrypt all your online transactions? Secure corporate intranets? Authenticate your Web sites? Whatever
security your site needs, you'll find the perfect solution here!
http://us.click.yahoo.com/Bre3tC/Q56CAA/yigFAA/dpFolB/TM
---------------------------------------------------------------------~->
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/