C Program stopped working after using scanf instead of var=0 : <p>So I have this code:</p>

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

int functie ( int v[], int nr, int z)
{
    int i,count;
    scanf("%d", &amp;z);
    for(i=0;i&lt;nr;i++) {
        if(z==v[i]) {
            count=count+1;
        }
    }
    return z;
}

int main()
{
    int i,nr,z;
    fscanf("%d", &amp;z);
    FILE *f;
    FILE *g;
    f=fopen("data-in.txt", "r");
    fscanf(f,"%d",&amp;nr);
    int *v=malloc(nr*sizeof(int));
    for(i=0;i&lt;nr;i++) {
        fscanf(f,"%d",&amp;v[i]);
    }
    g=fopen("data-out.txt", "w");
    fprintf(g,"%d %d", functie(v,nr,z));
    fclose(f);
    fclose(g);
    free(v);
}
</code></pre>

<p>and before I had int z=0; instead of trying to scanf my var z.
When I run this I get a stopped working error.</p>

<p>I have an array with numbers (integers) read from file, first line is the number of elements and second line the elements.
I need a var lets say z to check how many times an element appears in vector (check if scanned number z is equal to an element and +1 count )</p>

<p>example:</p>

<p>in file</p>

<p>4 (cuz I have 4 elements )</p>

<p>1 2 3 3 ( my elements )</p>

<p>than scan z as 3
z==3 true 
count=1
again
count=2</p>
