Hi all,
I am confused..whether i am trying which we cant do or I am doing wrong..I would say i am doing some mistake in the following chunk. all i wanted to do is take a bunch of strings into a string pointer array so that i can reuse them.
**********************************
char i[35];
char *j[5];
memset(i,0,sizeof(i));
for (lt=0;lt < 3; lt++) {
if(m==0)
strcpy(i, "Hello"
if(m==1)
strcpy(i, "Hi there"
if(m==2)
strcpy(i,"How r ya"
j[lt]=i;
printf("i - %s, lt - %d, j - %s\n",i,lt,j[lt]);
m++;
}
printf("Value of j[0] j[1] j[2] is :%s %s %s \n",j[0],j[1],j[2]);
************************
The above chunk always gives me the last string. for all the three locations.
it prints
How r ya How r ya How r ya
but i need
Hello Hi there how r ya
All i need to do is make a pointer array of those three strings..I proceeded the above way by seeing the example of Tokenizing using strtok where we take all tokens into array of pointers..
Thanks in advance
logic4fun
I am confused..whether i am trying which we cant do or I am doing wrong..I would say i am doing some mistake in the following chunk. all i wanted to do is take a bunch of strings into a string pointer array so that i can reuse them.
**********************************
char i[35];
char *j[5];
memset(i,0,sizeof(i));
for (lt=0;lt < 3; lt++) {
if(m==0)
strcpy(i, "Hello"
if(m==1)
strcpy(i, "Hi there"
if(m==2)
strcpy(i,"How r ya"
j[lt]=i;
printf("i - %s, lt - %d, j - %s\n",i,lt,j[lt]);
m++;
}
printf("Value of j[0] j[1] j[2] is :%s %s %s \n",j[0],j[1],j[2]);
************************
The above chunk always gives me the last string. for all the three locations.
it prints
How r ya How r ya How r ya
but i need
Hello Hi there how r ya
All i need to do is make a pointer array of those three strings..I proceeded the above way by seeing the example of Tokenizing using strtok where we take all tokens into array of pointers..
Thanks in advance
logic4fun