[ale] Stupid question

Christopher Fowler cfowler at outpostsentinel.com
Mon Oct 29 18:38:18 EST 2001


I though of using one big buffer and storying everything there.  I would
know the exact locations
of everything.

Problem.

If my int is at 1 and hostname is 2-33 (32 bytes) , how to I access that
easily.

I.E:

char *buffer;

buffer = (char *)malloc(CONFIGSIZE);


/* Do some stuff like read /etc/config */

printf("APPS: %d\n", buffer[0]);

/* this will not work */
printf("HOSTNAME: %s\n", buffer[2-33]);

What would be the best approach to read and write config files that have a
lot of information that can be different like that.  I would love to see
some Howto's on the subject.

Chris

-----Original Message-----
From: ,,, [mailto:fultongr at greenie.frogspace.net]On Behalf Of Fulton
To: ale at ale.org
Green
Sent: Monday, October 29, 2001 6:13 PM
To: Christopher Fowler
Cc: ale at ale.org
Subject: Re: [ale] Stupid question


The question itself wasn't stupid, but leaving out the name of your
development language was. ;-)

If this is C/C++, that "int" needs to be a "char" instead, and IIRC, should
actually be a "short char", as some 32-bit platforms may try to use 16 bits
(i.e., 2 bytes) for the character representation.

It would also help to know which function you're using to write the
structure
out, as well as how you're using it.

On Mon, Oct 29, 2001 at 05:55:13PM -0500, Christopher Fowler wrote:
> When I write the folling:
>
> int c ='A'
>
> to a file, the file is 4 bytes in size.  In realsity that value could be
> stored in one byte.
>
> When I look at the file, it looks like this:
>
> A	NULL		NULL		NULL
>
> using octal dump with the ascii option.  I'm trying to build a config file
> that is created from
> a sturcture of values.  The structure is very big.  My calculations of
> locations were so wrong due to
> ths size of an interger being 4 bytes on my machine.  Is there a way to
make
> the interger actually
> 1 byte so that the only thing in the file is A.

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.




---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list