Estoy desarrollando un programa que facture, estoy utilizando archivo y estructuras.
El asunto esta en que cuando trato de mostrar el inventario, la sección precio me muestra basura y no le consigo la vuelta
lo único que hace es guardar y mostrar los productos lo demás lo tengo aparte
código:
#include <stdio.h>
typedef struct biblioteca{
int cod;
char nombre[10];
char editorial[15];
int precio;
}libros;
libros crear(int i){
libros x;
x.cod=i;
printf("\nNombre del libro: ");
scanf("%s",&x.nombre);
printf("\nEditorial del libro: ");
scanf("%s",&x.editorial);
printf("\nPrecio del libro: ");
scanf("%d",&x.precio);
return x;
}
void guardar(FILE *p,libros x){
if(p=(fopen("Productos.txt","a+"))){
fprintf(p,"%d %s %s %d\n",x.cod,x.nombre,x.editorial,x.precio);
printf("\n PRODUCTOS GUARDADOS CORRECTAMENTE \n");
fclose(p);
}
else printf("\n\n Error :( Algo salio mal! \n");
}
void inventario(FILE *p){
libros aux;
p=fopen("Productos.txt","r");
if(p!=NULL){
printf("LISTA TOTAL DE LIBROS: \n\n");
printf("%5s%15s%15s%10s\n\n","CODIGO","LIBRO", "EDITORIAL","CANTIDAD");
while(feof(p)==0){
fscanf(p,"%d %s %s %d\n",&aux.cod,aux.nombre,aux.editorial,aux.precio);
printf("%5d%15s%15s%10d\n",aux.cod,aux.nombre,aux.editorial,aux.precio);
}
fclose(p);
}
else printf("\n\nError :( Algo salio mal! NO HAY REGISTROS\n");
}
int main(){
int ac,i=0;
FILE *p;
int opc;
do{
printf("\n\n\t..::BIENBENIDO AL SISTEMA::..\n\n");
printf("\n\n\t\t1.-Vender\n\t\t2.-Registrar cliente\n\t\t3.-Mostrar inventario\n\t\t4.-Agregar libro\n\t\t0.-Salir\n\n\n");
scanf("%d",&opc);
system("cls");
if(opc==3){
inventario(p);
}
if(opc==4){
i++;
guardar(p,crear(i));
}
}while(opc!=0);
}
gracias de antemano!