score getscores[DATA];
fp = fopen("data.dat", "rb");
for (i = 0; i < DATA; i++) {
fread(&getscores[i], sizeof(getscores[i]), 1, fp);
printf("id:%d\tname:%s\tscore:%d\tdate:%s\n", getscores[i].id, getscores[i].name, getscores[i].score, ctime(&getscores[i].date));
}
fclose(fp);
}
int main(void) {
int i = 0;
score scores[DATA];
for (i = 0; i < 10; i++) {
scores[i].id = i+1;
strcpy(scores[i].name, "JUN");
scores[i].score = 10000-1000*i;
scores[i].date = time(NULL);
printf("id:%d\tname:%s\tscore:%d\tdate:%s\n", scores[i].id, scores[i].name, scores[i].score, ctime(&scores[i].date));
}
//scores[4].score = 8732;
FILE* fp;
fp = fopen("data.dat", "wb");
for (i = 0; i < DATA; i++) {
fwrite(&scores[i], sizeof(scores[i]), 1, fp);
}
fclose(fp);