Code:
#include <stdio.h>
int main(){
FILE *ifp;
ifp = fopen ("input.txt", "r");
int alpha, scores [3], i, bravo[18], charlie;
fscanf (ifp, "%d", &alpha);
printf ("alpha = %d\n", alpha);
for (i = 0; i<18; i++){
fscanf (ifp, "%d", &bravo[i]);
printf (" bravo = %d\n", bravo[i]);
}
printf ("alpha = %d", alpha);
for (i=0; i < 4; i++)
scores[i] = 0;
printf ("alpha = %d", alpha);
return 0;
}
input file:
1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
When I run this code, the value of alpha is '1' after the initial scanf. But after I get down to this loop to initialize the 'scores' array:
for (i=0; i < 4; i++)
scores[i] = 0;
The value changes to '0'. I don't understand why this initialization loop would change the value of alpha. Any help would be appreciated.