C - fscanf not reading number correctly from text file
<p>I am new to C and I am trying to make my int a equal to 4. The 4 is being read from a text file however when I print a out it prints out 32767.</p>

<pre><code>#include &lt;cstdlib&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include "Component.h"
using namespace std;


int main(int argc, char** argv) {
    FILE *fp;
    fp=fopen("text.txt","r");
    int a;

    fscanf(fp,"%d",&amp;a);
    if(fp == NULL) {
        printf("cannot open");
    }

    printf("%d",a);
}
</code></pre>