Base De Datos
#include
#include
#include
struct datos_clientes
{
char clave[4];
char nombre[40];
char calle[50];
char colonia[40];
char telefono[11];
}clientes;
struct datos_productos
{
char clave[4];
char producto[20];
char descripcion[40];
char precio[10];
}productos;
struct datos_factura
{
char clave[4];
charfecha[15];
char clave_cliente[4];
char clave_producto[4];
char cantidad[5];
}facturas;
void main()
{
int opcion=9;
int cantidadprod;
char opcion_seg[2];
char clavebuscar[4];
FILE *archivo, *auxiliar;
float precioprod;
char variablecomp;
int cont;
float totalpagar;
if((archivo=fopen("c:datoscli.txt","a+b"))==NULL)
{printf("\nNo se puede abrir el archivo");
getch();
exit(1);
}
if((auxiliar=fopen("c:borrador.txt","a+b"))==NULL)
{
;
printf("\nNo se puede abrir el archivo");
getch();
exit(1);
}
do
{
clrscr();
printf("\n Mini Super-Mercado ");
printf("\n######################################");
printf("\n 1.- Factura deVenta");
printf("\n 2.- Ingresar Nuevo Producto");
printf("\n 3.- Ingresar Nuevo Cliente");
printf("\n 4.- Buscar Factura de una Venta");
printf("\n 5.- Buscar Producto");
printf("\n 6.- Buscar Cliente");
printf("\n 7.- Salir");
printf("\n Opcion : ");
gets(opcion_seg);
opcion=atoi(opcion_seg);
switch(opcion)
{
case 1:clrscr();
freopen("c:datosfact.txt","a+b",archivo);
printf("\nClave de la factura: ");fflush(stdin);
gets(facturas.clave);
printf("\nFecha: ");fflush(stdin);
gets(facturas.fecha);
printf("\nClave del cliente: ");fflush(stdin);
gets(facturas.clave_cliente);
freopen("c:datoscli.txt","a+b",archivo);
rewind(archivo);variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&clientes,sizeof(clientes),1,archivo)!=1)
{
printf("\n Errror al leer producto");
getch();
exit(3);
}
if(strcmp(facturas.clave_cliente,clientes.clave)==0)
{
cont=2;
printf("\n Nombre: %s",clientes.nombre);}
variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
}
if (cont!=2)
{
printf("\n Clave del cliente no existe");
getch();
}
printf("\nClave del producto: ");fflush(stdin);
gets(facturas.clave_producto);
freopen("c:datosprod.txt","a+b",archivo);
rewind(archivo);variablecomp=fgetc(archivo);
fseek(archivo,0L,SEEK_SET);
while(variablecomp!=EOF)
{
if(fread(&productos,sizeof(productos),1,archivo)!=1)
{
printf("\n Errror al leer producto");
getch();
exit(3);
}
if(strcmp(facturas.clave_producto,productos.clave)==0)
{
cont=2;
precioprod=atof(productos.precio);printf("\n %s",productos.producto);
printf("\n Precio : %s",productos.precio);
printf("\n Cantidad de productos: ");
gets(facturas.cantidad);
cantidadprod=atoi(facturas.cantidad);
totalpagar=(precioprod)*(cantidadprod);
printf("\n Total a pagar= %f ", totalpagar);
getch();
}
variablecomp=fgetc(archivo);fseek(archivo,0L,SEEK_SET);
}
if (cont!=2)
{
printf("\n Clave ingresada no existe");
getch();
}
freopen("c:datosfact.txt","a+b",archivo);
if(fwrite(&facturas,sizeof(facturas),1,archivo)!=1)
{
printf("\n Error al escribir sobre el archivo");
getch();
}
break;
case 2:
clrscr();...
Regístrate para leer el documento completo.