After a lot of work I managed to write and generate a binary file, but when I want to read it I get strange characters and not what it generates, the strange thing is that at the end of the function of writing the file, after closing, I open and I can read it correctly but not from another side.
FILE *infile;
paisesBolillero input;
infile = fopen ("paisesBolillero.dat", "rb");
if (infile == NULL)
{
fprintf(stderr, "\nError opening file\n");
exit (1);
} else {
cout << "Se abrio" << endl;
}
while(fread(&input, sizeof(struct paisesBolillero), 1, infile)) {
cout << "PAIS: " << input.pais << endl;
cout << "BOLILLERO: " << input.bolillero << endl;
cout << "CONFEDERACION: " << input.confederacion << endl;
cout << "GRUPO: " << input.grupo << endl;
cout << "LIBRE: " << input.libre << endl;
cout << " - - - - - - - - - - - - - - - -" << endl;
}
fclose(infile);
That's the function I have, it does not work if the program starts wanting to read the file, but it works if I read it after generating it.
What can it be?