Good day to everyone,
there's some kind of big deal that I cannot figure out. I create a multidimensional array of pointers:
char *listA[5000][2];
In particular condition, I want that specific strings are saved inside this array. These are a normal string, in a simple variable, and another contained inside an array of strings.
listA[j][0]=strMix;
listA[j][1]=ingredients[i];
j++;
j, of course, is the row, that is increased for every adding.
The result must be an array that, for every row, contains two columns, one whit an ingredient, and another with the relative strMix.
The problem is that when I try to read this multidimensional array:
printf( "%s", listA[0][1]); // the ingredient
is always correct, but:
printf( "%s", listA[0][0]); // the strMix code
is always incorrect; precisely it reads the last strMix read, for every row.
I tried to change the order of the columns, and with my big surprise, the problem is always for the strMix, and never for the ingredients[i] string.
strMix column is correct only if I write it inside listA, and immediately read it. Of course, I'd say.
For example:
printf("Current: %s vs Previously: %s",lista[j][0], lista[j-1][0]);
they are the same, for every j, equal to the last strMix read.
If you have any ideas, something about memory or multidimensional array of pointers that I simply are missing, I'd appreciate your advises.
Thank you for the time, in every case. fdt.