Note that there are some explanatory texts on larger screens.

plurals
  1. POcant assign values to file variable
    text
    copied!<p>im quite new to C, and im trying to populate a file wide array variable with the results of a function, heres a simple code sample to show what i mean, can anyone point me in the direction of why this doesnt work?</p> <pre><code>#include &lt;sys/types.h&gt; #include &lt;dirent.h&gt; #include &lt;regex.h&gt; #include &lt;stdio.h&gt; #include &lt;gtk/gtk.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;pwd.h&gt; static gchar *external_names; void directories(int arraylength, gchar internal_names[][100]){ int n; for (n = 0; n &lt; arraylength; n++) { strcpy(external_names[n], internal_names[n]); } for (n = 0; n &lt; arraylength; n++) { printf("%s internal with %s external\n",internal_names[n], external_names[n]); } } void main() { gchar anotherarray[10][100]; directories(10, anotherarray); } </code></pre> <p>[EDIT] latest code</p> <pre><code>#include &lt;sys/types.h&gt; #include &lt;dirent.h&gt; #include &lt;regex.h&gt; #include &lt;stdio.h&gt; #include &lt;gtk/gtk.h&gt; #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;pwd.h&gt; static gchar *external_names[100]; void directories(int arraylength, gchar internal_names[][100]){ int n = 0; //gchar external_names[arraylength][100]; for (n = 0; n &lt; arraylength; n++) { printf("%s %i\n","before", n); strcpy(external_names[n], internal_names[n]); printf("%s %i\n","after", n); } } void main() { int n; gchar anotherarray[10][100]; for (n = 0; n &lt; 10; n++) { strcpy(anotherarray[n],"test"); } directories(10, anotherarray); for (n = 0; n &lt; 10; n++) { printf("%s internal with %s external\n",anotherarray[n], external_names[n]); } } </code></pre>
 

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