[ad_1]
Im working on this funtion that saves a structure into a file and then shows it on another function.
The problem is that only the last structure gets saved/printed. Wonder if you guys can help me fix this one up.
void CargaArchivoConsumo(char nombreArchivo[])
{ ///this function loads the struc into the file
stConsumo c;
char opcion;
FILE *archi=fopen(nombreArchivo,"ab");
if(archi)
{
do
{
c=cargaConsumo();
fwrite(&c,sizeof(stConsumo), 1, archi);
printf("\nPresione ESC para salir, cualquier tecla para continuar");
fflush(stdin);
opcion=getch();
}while(opcion!=ESC);
fclose(archi);
}
}
void muestraArchivoConsumo(char nombreArchivo[])
{ ///this function shows struct saved onto the file.
stConsumo c;
FILE *archi= fopen(nombreArchivo, "rb");
if(archi)
{
while(fread(&c, sizeof(stConsumo),1,archi)>0);
{
muestraUnConsumo(c);
}
fclose(archi);
}
}
[ad_2]