this is the code I tested:
Code:
#include <stdio.h>
struct student {
int ID;
char Name[50];
char Date[10];
float Min_temp;
float Max_temp;
int Valid;
} record[20];
int main(){
int i, x;
for(i = 0; i < 20; i++)
record[i].Valid = 1;
scanf("%d", &x);
record[x].Valid = 0;
for(i = 0; i < 20; i++)
printf("%2d: %d\t", i, record[i].Valid);
return(0);
}
I named it "1.cpp" and then compiled it.
this is the result:
Code:
1.exe
3
0: 1 1: 1 2: 1 3: 0 4: 1 5: 1 6: 1 7: 1 8: 1 9: 1
10: 1 11: 1 12: 1 13: 1 14: 1 15: 1 16: 1 17: 1 18: 1 19: 1
1.exe
5
0: 1 1: 1 2: 1 3: 1 4: 1 5: 0 6: 1 7: 1 8: 1 9: 1
10: 1 11: 1 12: 1 13: 1 14: 1 15: 1 16: 1 17: 1 18: 1 19: 1
1.exe
9
0: 1 1: 1 2: 1 3: 1 4: 1 5: 1 6: 1 7: 1 8: 1 9: 0
10: 1 11: 1 12: 1 13: 1 14: 1 15: 1 16: 1 17: 1 18: 1 19: 1
It seems nothing wrong.
You may have a try to add
printf("%d\n", x);
before
record[x].Valid = 0;
to see if "x" has strange value.