|
From: Rafael C. <rc...@un...> - 2005-04-26 14:53:52
|
> Alexsandro Meireles wrote:
> array[0] = "sentence 1";
> array[1] = "sentence 2"
> and so on...
There are some ways I can remember.
The point is defining your array as
an array to char pointers.
//initializing an array of strings
char* sentences[2]={"sentence 1", "sentence 2"};
//assigning strings to the array
char* sentences[2];
sentences[0]="another sentence 1";
sentences[1]="another sentence 2";
/* allocating memory dinamically and copying
the string */
strings[0]=(char *)malloc(sentenceLength + 1);
strcpy(strings[0],"sentence 1 again");
It could be also an bidimensional array of char, but
I'd rather use pointers:
char sentences[20][101]; //20 sentences with a limit of 100 characters
Maybe other developers have more suggestions.
I sent a program (attached) just as an example.
Hope it helps,
Rafael
|