0
Function that writes and reads binary file:
int FUNCAO_QUE_GRAVA_BIN (char filename[],int partida1,char resultado1)
{
typedef struct {
int partida;
char jogvelha[3][3];
char resultado;
} velha;
velha partida = {partida1,{"a","b"},resultado1},read_data;
FILE * file= fopen(filename, "wb");
if (file != NULL) {
fwrite(&partida, sizeof(velha), 1, file);
fclose(file);
FILE* fin = fopen(filename, "rb");
fread(&read_data, sizeof(velha), 1, file);
printf("%d %c %c\n", read_data.partida, read_data.jogvelha[3][3], read_data.
resultado);
fclose(fin);
fflush(stdin);
while(getchar()!='\n'); // option TWO to clean stdin
getchar(); // wait for ENTER
return 0;//failure //ignore
}
return 1; //sucesso /ignore
}
calling on the main :
int ganhador=1;
char local[]={"binar"};
int partidas= 1;
FUNCAO_QUE_GRAVA_BIN(local,partidas,ganhador);
the problem is that the output is going all wrong, the game[3][3] does not come out right, as tidy?
If
jogvelha
is an array of 3 by 3, soread_data.jogvelha[3][3]
is wrong. An array of size 3 has boxes 0, 1 and 2– Isac
@Isac on the printf you say?
– lucas pelepek
Yes in the
printf
– Isac
@Isac
printf("%d %c %c\n", read_data.partida, read_data.jogvelha[0][1], read_data.
 resultado);
output:1, letra do ASCII
not only is the output of theread_data.resultado
– lucas pelepek