C Reading numbers from file into array
<p>hey so i m trying to read numbers from text file and put them into an array but ive been getting weird numbers when i try to print them. text file looks like:</p>

<pre><code>45
77
8
...
</code></pre>

<p>i guess theres something wrong with the loop i m using but i cant seem to find out what.
thanks for your help!</p>

<p>code:</p>

<pre><code>#define MAX_ARRAY_SIZE 20

int main(int argc, char * argv[])
{
    FILE *myFile;
    int myArray[MAX_ARRAY_SIZE];
    //char filename[32];
    //printf("enter filename\n");
    //scanf("%s", filename);

    myFile = fopen("asdf.txt", "r");
    if (!myFile) {
        printf("cant open file\n");
        return 1;
    }
    int status;
    int i = 0;
    while ((status = fscanf(myFile, "%2d", &amp;myArray[i])) == 1 &amp;&amp; i &lt; MAX_ARRAY_SIZE - 1) {
        ++i;
    }
    fclose(myFile);


    int a;
    for (a = 0; i &lt; MAX_ARRAY_SIZE; ++i) {
        printf("%d ", myArray[i]);
    }
    printf("\n");
return 0;
}
</code></pre>