ManelBit    manel666xq@hotmail.com Fecha  18/05/2009 17:14 
Host: No mostrado/ Not shown    IP: No mostrado/ Not shown    Sistema: Windows XP


Volver al foro Responder ayuda por favor con programa de base de datos   Admin: Borrar 	mensaje
 
Mensaje
Publicidad
tengo este programilla en c y al compilarlo no m da errores pero luego no funciona, haber si alguien ve el fallo y es tan amable de ayudarme



/* MENU GENERAL*/
# include <stdio.h>
# include <conio.h>
# include <process.h>
# include <string.h>
# include <ctype.h>
void intro (void);
void modif (void);
void borra (void);
void consu (void);
void error (void);
struct {
char nombre[30];
char direccion [25];
char telefono [12];
char poblacion [10];
}datos; /*el conjunto de cuatro campos.ficha*/
FILE *fichero; /*el nombre del fichero*/
char opc, nom[30]; /*opc -----opcion*/
int tama; /*tama----tamaño*/
/*Principio de programa*/
void main()
{
for(;;){
clrscr();
gotoxy (38,5); printf ("MENU");
gotoxy (29,8); printf ("1_introducir registros");
gotoxy (29,10); printf ("2_modificar registro");
gotoxy (29,12); printf ("3_Borrar registros");
gotoxy (29,14); printf ("4_ Consultar registros");
gotoxy (29,16); printf ("5_Finalizar");
gotoxy (19,19); printf(" Introduce el numero de la opcion deseada");
opc=getch ();
switch (opc){
case'1': intro(); break;
case'2': modif(); break;
case'3': borra(); break;
case'4': consu(); break;
case'5': exit(0);
default : break;
}
}
}
/*Grabar datos*/
void intro (void)
{
clrscr();
if(((fichero)=fopen ("agenda.dat","ab"))==NULL) error();
for (;;){
gotoxy (20,6); printf ("para finalizar pulse la tecla ENTER.");
gotoxy (20,9); printf ("nombre------:");
gotoxy (20,11); printf ("direccion----:");
gotoxy (20,13); printf ("telefono-----:");
gotoxy (20,15); printf ("Población---:");
gotoxy (34,9); gets(datos.nombre);
if (strlen(datos.nombre)==0)break;
gotoxy (34,11);gets (datos.direccion);
gotoxy (34,13);gets (datos.telefono);
gotoxy (34,15);gets (datos.poblacion);
gotoxy (20,18);printf ("datos correctos (s/n):");
opc=toupper (getch ());
if (opc=='S');
fwrite (&datos,sizeof (datos),1,fichero);
}
fclose(fichero);
}

/* funcion modificar registros*/
void modif (void)
{
clrscr();
tama = sizeof (datos);
if (((fichero)=fopen(" agenda.dat","r+b"))==NULL) error();
gotoxy (15,12); printf ("Introduce el nombre a modificar");
gets (nom);
clrscr ();
while ( !feof (fichero)){
fread (&datos, sizeof (datos), 1, fichero);
if (strcmp (datos.nombre, nom)==0){
gotoxy (18,7); printf ("1 _ nombre :%S ",datos. nombre);
gotoxy (18,9); printf ("1 _ dirección:%S",datos. direccion);
gotoxy (18,11); printf ("3 _ telefono:%S",datos. telefono);
gotoxy (18,13); printf ("4 _ poblacion:%S",datos. poblacion);
gotoxy (18,16); printf ("5_ fin de modificaciones");

while (opc=='5'){
gotoxy (18,19); printf ("campo a modificar");
opc=getch();
gotoxy (18,19); clreol ();
switch (opc){
case'1': gotoxy (37,7); clreol(); gets (datos.nombre); break;
case'2': gotoxy (37,9); clreol(); gets (datos.direccion); break;
case'3': gotoxy (37,11); clreol(); gets (datos.telefono); break;
case'4': gotoxy (37,13); clreol(); gets (datos.poblacion); break;
case'5': fseek (fichero,tama, SEEK_CUR);
fwrite (&datos, sizeof (datos),1,fichero); break;
default: break;
}
}
break;
}
}
fclose(fichero);
}

/*borrar registros*/
/*funcion para borrar registros*/
void borra (void)
{
clrscr();
tama=sizeof (datos);
if (((fichero)=fopen("agenda.dat","r+b"))==NULL)
error ();
gotoxy (15,12); printf ("Introduce el nombre a borrar:");
gets (nom);
clrscr();
while (!feof (fichero)){
fread (&datos, sizeof (datos),1, fichero);
if(strcmp(datos.nombre, nom)==0){
gotoxy (20,7); printf ("nombre: %S", datos.nombre);
gotoxy (20,9); printf ("nombre: %S", datos.direccion);
gotoxy (20,11); printf ("nombre: %S", datos.telefono);
gotoxy (20,13); printf ("nombre: %S", datos.poblacion);
gotoxy (20,15); printf ("estas seguro de querer borrarlo(s/):");
opc=toupper (getch ());
clrscr();
if (opc=='5'){
strcpy (datos.nombre,"*");
fseek (fichero,tama, SEEK_CUR);
fwrite (&datos, sizeof (datos),1,fichero);
break;
}
}
}
fclose (fichero);
}
/*Funcion de error de abertura*/
void error (void)
{
clrscr();
printf ("error!. No se puede abrir el fichero!");
getch();
exit (0);
}
/* imprimir fichero*/
void imprime (void)
{
FILE *imp; /*definicion de la propia impresora com a fitxer */
int indice;
if (((fichero)=fopen("agenda.dat","r+b"))==NULL) error();
gotoxy (15,22); printf ("imprimiendo fichero...");

/*abrr el fichero de impresora */
imp= fopen("prn","W");
indice=1;
while (!feof (fichero)){
fread (& datos, sizeof (datos), indice, fichero);
}
/*Imprime el registro*/
fprintf (imp,"%S%S%S%S\n",datos.nombre, datos.nombre,
datos.direccion,datos.telefono,datos.poblacion);
/*incrementa el indice del registro*/
indice++;
{
fcloseall();/*cierra todos los ficheros*/
}
}
                                                                                                                                                                                                                                                                                                                               
 

Respuestas (0)
 
  • » ayuda por favor con programa de base de datos « - ManelBit - 18/05/2009 17:14


Volver Responder
 
Nombre
E-Mail
Asunto
Web
Enlace a una
imagen

Mensaje