TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: All
from: Len Philpot
date: 2004-01-27 20:31:44
subject: Re: [C] Question about external variable initialization

From: "Len Philpot" 

>  LP> char text[12];
>  LP> text = "Some text";
>
> Hmm.. I doubt it would work, but I can't explain why, because you may
> initialize a array in that way.

It _shouldn't_, since the name of the 'string' (as a character array) is
really just a pointer to the first element of the array. I don't know of
any way to assign a string of text to a pointer except by defining and
initializing it at the same time (char *text="text";)... but then
again, there's a lot I don't know.


>  LP> Just as an aside, how portable is strdup()?
>
> Should be very portable, else you can make it:

Just curious - Although I see it here and there on the Single Unix
Specification (and PC compilers), it's apparently not a part of ISO C.


>  LP> However in this case, I know exactly how much
>  LP> data there is - The large "character set", and it won't
>  LP> change (usually famous last words, but I think it's
>  LP> true here :-) In the case of my banner workalike, it is
>  LP> a 760 element array, each group of eight 8-character
>  LP> elements comprising one large character. Hence my
>  LP> desire to move 760 lines of initialization out of the main file.
>
> Hmm.. I'm not sure I understand.

For example :
        char *chr[] = {
                " ###### ",
                " ###### ",
                "   ##   ",
                "   ##   ",
                "   ##   ",
                "   ##   ",
                "   ##   ",
                "        " };

...and so on, except there are a total of 760 elements, for the other 94
characters banner supports (or at least did in the implementation I used to
create my characters). A formula figures the offset into the array for a
given character and the entire string is displayed one "pixel" at
a time (cols x rows). As you can guess, it takes up a fair amount of file
space to assign all these values.

I've since come up with a scheme to use an integer array (I guess it
_could_ be unsigned char) where each element contains a bitmask value
between 0 and 255 of the elements as shown above. A function converts the
value to a string and displays it. Makes the initialization of the array
take up less space and no pointers to dink with... :-) Although since I'm
doing this for my own edification I should use pointers _everywhere_ I can
just to immerse myself in them... I understand the /basic/ concepts, but
between giant lapses in contact with C and other missing mental
functionality , I tend to overlook and misunderstand things more
often that I'd like.

Thanks again.

--
 -- Len Philpot -> len{at}philpot.org     <--
 ------ > -----> http://philpot.org/ <--

--- BBBS/LiI v4.01 Flag-5
* Origin: Prism's_Point (1:261/38.1)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.