I have this simple program where I am trying to return a pointer to an array of chars, the output comes something like:
0 : lllkkknnn
1 : kkknnn
2 : nnn
where the first element in the array aa[][] takes all the variables of the other elements in the same array.
I want the output to be something like:
0 : lllkkknnn
1 : kkknnn
2 : nnn
Appreciate your help.
Code
=============== =============== =======
char* negotiateKeysMa ster();
int main()
{
char* aa;
int i;
aa = negotiateKeysMa ster());
printf("0 : %s \n",aa[0]);
printf("1 : %s \n",aa[1]);
printf("2 : %s \n",aa[2]);
return 0;
}
char* negotiateKeysMa ster()
{
char keysChar[3][3];
strcpy(keysChar[0],"lll");
strcpy(keysChar[1],"kkk");
strcpy(keysChar[2],"nnn");
return &keysChar;
}
0 : lllkkknnn
1 : kkknnn
2 : nnn
where the first element in the array aa[][] takes all the variables of the other elements in the same array.
I want the output to be something like:
0 : lllkkknnn
1 : kkknnn
2 : nnn
Appreciate your help.
Code
=============== =============== =======
char* negotiateKeysMa ster();
int main()
{
char* aa;
int i;
aa = negotiateKeysMa ster());
printf("0 : %s \n",aa[0]);
printf("1 : %s \n",aa[1]);
printf("2 : %s \n",aa[2]);
return 0;
}
char* negotiateKeysMa ster()
{
char keysChar[3][3];
strcpy(keysChar[0],"lll");
strcpy(keysChar[1],"kkk");
strcpy(keysChar[2],"nnn");
return &keysChar;
}
Comment