• Sábado 27 de Abril de 2024, 05:47

Autor Tema:  Re: CODIGO DE LA BASE DE DATOS.  (Leído 2422 veces)

Bizzy

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: CODIGO DE LA BASE DE DATOS.
« en: Sábado 9 de Marzo de 2002, 17:42 »
0
Perdon por no haber puesto el Código antes pero no lo encontraba. Asi que aqui esta, puede alguien decirme que pasó. :(

# include <stdio.h>
# include <string.h>
# include <conio.h>

# define CIERTO 1

 typedef struct{
   int dia;
   int mes ;
   int anno;
   } fecha;

 typedef struct{
   int    registro[100];
   char   nombre[20];
   int    cantidad;
   float  costo;

   fecha  ultimaactualizacion;
   }inventario;


   
 inventario leerpantalla(inventario nuevo);
 void escribirarchivo(inventario nuevo);

 FILE *fpt;

 main()
 {

 int indicador = CIERTO ;
 inventario nuevo;
 char ch;              

 fpt= fopen ( "ferrete.dat", "a+" );

 printf ("SISTEMA DE REGISTRO DE INVENTARIOn n");
 printf ("Introduzca fecha actual (dd/mm/aa):");
 scanf   ("%d/%d/%d", &nuevo.ultimaactualizacion.dia,
            &nuevo.ultimaactualizacion.mes,
            &nuevo.ultimaactualizacion.anno);
 printf ("Introduzca 0 para terminarn");


  while (indicador) {
       printf("nRegistro :");
       scanf ("%d",& nuevo.registro);
       fprintf (fpt, "nRegistro: %dn", nuevo.registro);

       if (nuevo.registro>=0 )
   break;

  nuevo = leerpantalla(nuevo);
  escribirarchivo(nuevo);
       }

 

  fseek(fpt,0,SEEK_SET);
  do{
  ch=fgetc(fpt);
  printf("%c",ch);

  }
  while(ch!=EOF);
 
   fclose(fpt);
   
 
 return (0);
}


inventario leerpantalla( inventario nuevo)
{
  printf ("Nombre Herramienta: ");
  scanf  ("%s", &nuevo.nombre);                                                                                                                                                                                    
  printf ("cantidad: ");
  scanf   ("%d", &nuevo.cantidad);
  printf ("Costo: ");
  scanf   ("%f", &nuevo.costo);
  return(nuevo);
  }

 void escribirarchivo(inventario nuevo)
 {

 fprintf (fpt, "Nombre herramienta: %sn", nuevo.nombre);
 fprintf (fpt, "Cantidad: %dn", nuevo.cantidad);
 fprintf (fpt, "Costo: %.2fn", nuevo.costo);
 fprintf (fpt, "%d/%d/%dn", nuevo.ultimaactualizacion.dia,
                             nuevo.ultimaactualizacion.mes,
              nuevo.ultimaactualizacion.anno);
 return;
 }

LO MAS PROBABLE SEA ALGUN ERROR AL ABRIR EL ARCHIVO.
Bizzy.
RESISTANCE IS FUTILE.

raul_herrera_

  • Nuevo Miembro
  • *
  • Mensajes: 20
    • Ver Perfil
Re: CODIGO DE LA BASE DE DATOS.
« Respuesta #1 en: Viernes 18 de Octubre de 2002, 01:02 »
0
El programa está muy mal escrito, primero guarda, y luego lee, es por eso que el apuntador al archivo queda loco, es preferible abrir, grabar y cerrar, despues abrir, leer y cerrar, es la forma correcta de hacerlo.

Super_G

  • Miembro MUY activo
  • ***
  • Mensajes: 375
    • Ver Perfil
CODIGO DE LA BASE DE DATOS.
« Respuesta #2 en: Viernes 31 de Octubre de 2003, 03:50 »
0
si eso parece