I am trying to write in the cajeros.dat file the values that the user set to the actu variable which is a struct type. I don't get any error but when I check the file, the int values like "cod_cajero" and "den_menor" and "den_mayor" show like some random characters in the file. This is an example:
d El bravo Santiago ¸ýf
"El bravo" and "Santiago" are char values which were inserted correctly but "d" was actually a 100 and "¸ýf" were some other numbers. Can someone help me? I would really appreciate it
int actualizarcajeros();
struct e_cajeros{
int cod_cajero;
char ubicacion[20];
char ciudad[20];
int den_menor;
int den_mayor;
} actu;
int cajeros(){
int opcion1;
int consultarcajeros();
while(1){
printf("Menu Cajeros\n1.Actualizar.\n2.Consultar.\n3.Finalizar\n");
scanf("%d",&opcion1);
if(opcion1==1){
actualizarcajeros();
}
}
}
actualizarcajeros(){
FILE *fp;
fp=fopen("cajeros.dat","a");
printf("ingresa el codigo del cajero");
scanf("%d",&actu.cod_cajero);
printf("ingresa la ubicacion del cajero");
gets(actu.ubicacion);
printf("ingresa el ciudad del cajero");
gets(actu.ciudad);
printf("ingresa la denominacion menor");
scanf("%d",&actu.den_menor);
printf("ingresa la denominacion menor");
scanf("%d",&actu.den_mayor);
fwrite(&actu,sizeof(actu),1,fp);
fclose(fp);
}