1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
void savedata(scrabble variable){
int k, j;
FILE *save;
save = fopen("scrabble.txt", "w");
fprintf(save, "%d\n", variable.n);
fprintf(save, "%d\n", variable.p);
fprintf(save, "%d\n", variable.no);
for(k=1;k<=variable.no;k++){
fprintf(save,"%c\n",variable.players[k].tiles);
fprintf(save,"%d\n",variable.players[k].score);
}
for(k=1;k<=100;k++){
fprintf(save, "%d\n", variable.letter[k]);
}
for(k=0; k<24; k++){
for(j=0; j<=12; j++){
fprintf(save, " %c", variable.board[k][j]);
}
}
fclose(save);
}
scrabble loaddata(scrabble variable, int m){
int k, j, l;
FILE *load;
if ((load=fopen("scrabble.txt", "r"))==NULL){
variable.n=100;
variable.p = 1;
variable.no = 0;
strcpy(variable.letter, "AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGGHHIIIIIIIIIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZ ");
if(m==0){
m=m+1;
printf("No existing save game. Loading new game\n");
printf("%d", m);
}
}else{
fscanf(load, "%d\n", &variable.n);
fscanf(load, "%d\n", &variable.p);
fscanf(load, "%d\n", &variable.no);
for(k=1;k<=variable.no;k++){
fscanf(load,"%c\n",variable.players[k].tiles);
fscanf(load,"%d\n",&variable.players[k].score);
}
for(k=1;k<=100;k++){
fscanf(load, "%d\n", variable.letter[k]);
}
for(k=0; k<24; k++){
for(j=0; j<=12; j++){
fscanf(load, " %c", variable.board[k][j]);
}
}
}
fclose(load);
return variable;
}
|