TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Bo Simonsen
from: Jasen Betts
date: 2004-01-28 08:54:02
subject: [C] Question about external variable initialization

Hi Bo.

 LP>>         ext_char_arr[0] = "element zero";
 LP>>         ext_char_arr[1] = "element one";
 LP>>         ext_char_arr[2] = "element two";

 BS> Where do you malloc() those?

the above is legal if you don't modify what's pointed to.

 LP>> What precipitated this was a workalike of the 'banner'

(hmm, which banner program)

 LP>> program I wrote (called "pennant", naturally). The
 LP>> program is about 50 lines of code and 800+ of the large
 LP>> "character" definitions.

it's perfectly legal for that purpose as the definition are basically
constants...

 BS> If you have a unknown number of lines, you could use char**, or a linked
 BS> list (the linked list might be easier).

it's possible to do even that with constant arrays,

 char *shape1[]={"* *",
                 " * ",
                 "* *",
                 NULL}

 char *shape2[]={"*****",
                 "*   *",
                 "*   *",
                 "*   *",
                 "*****",
                 NULL}

 char **shapes[]={shape1,shape2,NULL};

 -=> Bye <=-

---
* Origin: I smell a rat. Did you bake it or fry it? (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 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™.