How do I return a struct (from a function) containing an array with the correct elements in that array?
<p>I'm making a program that returns a struct containing an array, but the elements in the array are completely wrong. I keep searching for an answer on this site, Google, and even Bing and nothing. The best I can find are answers like this:</p>

<blockquote>
  <p>Functions can't return arrays in C.<br>
  However, they can return structs. And structs can contain arrays...</p>
</blockquote>

<p>from <a href="https://stackoverflow.com/questions/14297169/how-to-make-an-array-return-type-from-c-function">How to make an array return type from C function?</a></p>

<p>Now, how do I fix this without the use of pointers?</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;math.h&gt;
#include &lt;stdlib.h&gt;  
#include &lt;ctype.h&gt;

struct Codes{
int as;
int a[];
};

struct Codes create(int as){
    int a[as];
    for(int j = 0;j&lt;as;j++)
        a[j]=j+1;
    struct Codes c;
    c.as = as;
    c.a[c.as];
    for(int i=0; i&lt;as; i++)
        c.a[i] = a[i];

    for(int i=0; i&lt;as; i+=1)
        printf("%d \n", c.a[i]);

    return c;
}

int main(int argc, char **argv) {

    struct Codes cd;
    int as = 4;
    cd = create(as);

    for(int i=0; i&lt;4; i+=1)
        printf("%d \n", cd.a[i]);

}
</code></pre>

<p>Actual output:</p>

<pre><code>1 
2 
3 
4 
0 
0 
2 
-13120 
</code></pre>

<p>Expected output:</p>

<pre><code>1 
2 
3 
4 
1
2
3
4
</code></pre>