Hi,
I am trying to make a array that can contain elements like this:
Array[0] = "p1";
Array[1] = "p2";
..
.
.
.
.
.
.
Array[99] = "p100";
how can I make such an array in C language.
Thanks a lot.
Hi,
I am trying to make a array that can contain elements like this:
Array[0] = "p1";
Array[1] = "p2";
..
.
.
.
.
.
.
Array[99] = "p100";
how can I make such an array in C language.
Thanks a lot.
Code:char *arrayofpointerstocharacters[ ARRAYSIZE ];
Quzah.
Hope is the first step on the road to disappointment.
At compile time (one possible way):At runtime (one possible way): declare array as a 2D char Array and use sprintf in a loop to fill it. More details on usage = better replies.Code:const char *text[100] = { "p1", /* ...the rest of them... */ "p100" };
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Thanks for the replies I will try it and let you know
make a 2-D char array
eg: array[100][10];
then declare array[0]="p1" etc
That won't work, you can't assign strings like that. You'd need to strcpy it into the array:Originally Posted by ramya
But if you're going to initialise them all statically, you might as well do it as has already been suggested in previous posts, with an initialisation list, or with a loop and sprintf.Code:strcpy(array[0], "p1");
Last edited by cwr; 10-27-2005 at 12:29 AM.