Help With Array of Pointers to chars

Everyone Knows JINX jinx at milton.u.washington.edu
Wed Apr 3 09:43:22 AEST 1991


jansa at cat27.cs.wisc.edu (Dean Jansa) writes:

>I a quick Question for all of you... 
>What is the fastest way, ( read efficent use of memory and quick ) to
>transfer strings from a struct i.e:

>	struct something 
>		  {
>		   string[10];
>		   string2[10];
>		   string3[10];
>		   .
>		   .
>		   .
>                  };
>into a array of pointers to chars:
>       char *myarray[10];

>I need to malloc each pointer to char to be able to hold 10 chars in this
>example then do a strcpy.   Any easier ways out there??

ummm... Let me geth this straight.

You want an ARRAY of 10 POINTERS to char. (char *myarray[10])
You have a STRUCT with 10 char ARRAYS. 
struct { 
char 	string[10][10];
} mystruct

can you just do a:

for(i=0; i != 10; i++)
   myarray[i] = mystruct.string[i];

or something like that?
( I slightly modified your original structure so taht it would work in
a loop, but I think you get the idea...)
You don't need to malloc space for an array of pointers. 

-- 
jinx at milton.u.washington.edu
Disclaimer:
OFS.*



More information about the Comp.lang.c mailing list