Note that there are some explanatory texts on larger screens.

plurals
  1. POMultidimensional array of char pointer
    primarykey
    data
    text
    <p>Good day to everyone,</p> <p>there's some kind of big deal that I cannot figure out. I create a multidimensional array of pointers:</p> <pre><code>char *listA[5000][2]; </code></pre> <p>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.</p> <pre><code> listA[j][0]=strMix; listA[j][1]=ingredients[i]; j++; </code></pre> <p><em>j</em>, of course, is the row, that is increased for every adding.</p> <p>The result must be an array that, for every row, contains two columns, one whit an ingredient, and another with the relative strMix.</p> <p>The problem is that when I try to read this multidimensional array:</p> <pre><code>printf( "%s", listA[0][1]); // the ingredient </code></pre> <p>is always correct, but:</p> <pre><code>printf( "%s", listA[0][0]); // the strMix code </code></pre> <p>is always incorrect; precisely it reads the last strMix read, for every row.</p> <p>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 <em>ingredients[i]</em> string.</p> <p>strMix column is correct only if I write it inside listA, and immediately read it. Of course, I'd say.</p> <p>For example:</p> <pre><code>printf("Current: %s vs Previously: %s",lista[j][0], lista[j-1][0]); </code></pre> <p>they are the same, for every j, equal to the last strMix read.</p> <p>If you have any ideas, something about memory or multidimensional array of pointers that I simply are missing, I'd appreciate your advises.</p> <p>Thank you for the time, in every case. fdt.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload