Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!ogicse!unicorn!milton!jinx From: jinx@milton.u.washington.edu (Everyone Knows JINX) Newsgroups: comp.lang.c Subject: Re: Help With Array of Pointers to chars Message-ID: <1991Apr2.234322.15613@milton.u.washington.edu> Date: 2 Apr 91 23:43:22 GMT References: <1991Apr2.193849.17442@daffy.cs.wisc.edu> Organization: University of Washington Lines: 43 jansa@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@milton.u.washington.edu Disclaimer: OFS.*