Programación General > C/C++

 Re: AGENDA

(1/1)

Anna:
Hola, tengo una agenda pero no va. Me da error de en:
void inicializar(agenda *c)
{
   int x;
   for(x=0;x<FIN;x++)
      c[x].id=0;
}

Y otros errores (creo que es culpa del malloc) en:
void introducir(agenda*c)
{
   int i=0;
   char nombre[20];
   char apellidos[30];
   char telefono[12];
   char resp='s';
   while(tolower(resp)=='s')
   {
      do
      {
         printf("Introducir datosn");
         flushall();
         printf("Introduce nombre:n");
         flushall();
         gets(nombre);
         c->nombre=*(char*)malloc(strlen(nombre+1)*sizeof(char));
         strcpy(c->nombre,nombre);
         flushall();
         printf("Introduce apellidos:n");
         flushall();
         gets(apellidos);
         c->apellidos=(char*)malloc(strlen(apellidos+1)*sizeof(char));
         strcpy(c->apellidos,apellidos);
         flushall();
         printf("Introduce Telefono:n");
         flushall();
         gets(telefono);
         c->tel=(char*)malloc(strlen(telefono+1)*sizeof(char));
         strcpy(c->tel,telefono);
         flushall();
         printf("¿Datos correctosn?s/n");
         resp=getchar();
      }
      while (tolower(resp)!='s');
      i++;
      printf("Desea introducir más personasn (s/n)");
      resp=getchar();
      flushall();
   }
}

Al ejecutarlo, da error de no poder written.
Dejo todo el código, haber si alguien me puede echar una mano.
:question:

JuanK:
quisiera ayudarte pero ultimament no dispongo de mucho tiempo, asi que seria de gran ayuda si anotas que errores te salen.

Anna:
Gracias por ayudarme.
Al ejecutarlo sale el mensaje:
"Agenda_si provocó un error en AGENDA_SI.EXE.
Agenda_si se cerrará.
Si continuán los problemas, pruebe de nuevo después de reiniciar el equipo."

Si elijo depurar sale el mensaje:
"Unhandled exception in agenda_si.exe: 0xC0000005: Access Violation"
y señala a:
void inicializar(agenda *c)
{
   int x;
   for(x=0;x<FIN;x++)
      c[x].nombre=0; //A esta línea.
}

Además da los siguientes warnings. No sé si tendrá que ver con el error:
warning C4047: '==' : 'char *' differs in levels of indirection from 'int       if(c[x].nombre==inicial)// Señala esta línea.
warning C4700: local variable 'c' used without having been initialized
warning C4700: local variable 'b' used without having been initialized
warning C4700: local variable 'a' used without having been initialized
warning C4715: 'nuevaagenda' : not all control paths return a value
agenda *nuevaagenda()
{
  agenda *q = (agenda *)malloc(sizeof(agenda));
  if (!q)
  return q;
}
warning C4700: local variable 'x' used without having been initialized
warning C4700: local variable 'medio' used without having been initialized
warning C4700: local variable 'aux' used without having been initialized

Como ves, muchos son iguales. Los errores de "no inicializados" ya los entiendo. El resto no sé exactamente a que se refiere.:gracias:

JuanK:
bueno hay bastantes errores, pero veremos de a uno a la vez...
tu haces:
 
--- Código: Text ---  inicializar(&c);  per inicializar recibe:
 
--- Código: Text --- //STRUCTstruct agenda{ int id; char *nombre; char *apellidos; char *tel;};typedef struct agenda agenda;  //DECLARACIONES DE FUNCIONESint menu(void);void inicializar(agenda *c);void introducir(agenda*c);int consultar(agenda*c);void listado_quicksort(agenda*c,int a, int b);void eliminar(agenda*c);agenda *nuevaagenda();  
Asi que es incorrecto  porque agenda es una struct  lo cual nos dice que de por si es un apuntador a una estructura de datos... hacer esto:
 
--- Código: Text ---  inicializar(&c);  
Esta mal porque realmente estas pasando un parametro agenda**c.

lo correcto es:
 
--- Código: Text ---  inicializar(c);  
Asi tienes varios errores, verificalos y trata de resolver los demas, si continuan tus ñproblemas no dudes en consultar, se nota que has tratado de hacer un buen trabajo.:lightsabre:

Anna:
Gracias por la ayuda, seguiré tus consejos.
 Siempre me pasa igual con los punteros, nunca me aclaro.:gracias:

Navegación

[0] Índice de Mensajes

Ir a la versión completa