¿Dónde falla esta función?
Esta función implementa el borrado de personas en una hipotética agenda.
Nunca aparace la primera persona, con lo que borra la que no es. ¿Donde está
el error?
Gracias anticipadas.
****************************************************************************
*
* FUNCION BORRAR
*
****************************************************************************
****
*/
int borrar (int*r)
{
int i,del;
int opcion;
int mayuscula;
*r=cuenta_personas;
if (*r==0)
{
clrscr();
gotoxy(28,12);
cprintf("LA AGENDA ESTA VACIA");
getch();
return 1;
}
clrscr();
gotoxy(14,12);
cprintf("INTRODUCIR EL NUMERO DE PERSONA QUE DESEAS BORRAR : ");
textcolor(RED);
textbackground(WHITE);
scanf("%d",&del);
for(i=del;i<*r;i++)
{
cprintf("nn 255255255 A T E N C
I O N !!! ");
textcolor(30);
textbackground(BLACK);
cprintf("nr Se va a borrar la persona con indice %d: 256
%s %s %s 257
",i,datos[i-1].nombre,datos[i-1].primer_apellido,datos[i-1].segundo_apellido
);
gotoxy(19,18);
textcolor(WHITE);
textbackground(BLACK);
cprintf("n250Est240 seguro de querer continuar? (S/N): ");
do
{
opcion=getchar();
mayuscula=toupper(opcion);
if (mayuscula=='S')
{
strcpy(datos[i].nombre,datos[i+1].nombre);
strcpy(datos[i].primer_apellido,datos[i+1].primer_apellido);
strcpy(datos[i].segundo_apellido,datos[i+1].segundo_apellido);
strcpy(datos[i].direccion,datos[i+1].direccion);
strcpy(datos[i].telefono,datos[i+1].telefono);
strcpy(datos[i].movil,datos[i+1].movil);
*r=*r-1;
cuenta_personas=cuenta_personas-1;
gotoxy(20,19);
textbackground(GREEN);
cprintf("nSe ha borrado la persona con indice %d",i);
gotoxy(1,25);
cprintf("250Deseas actualizar el archivo de disco? (S/N): ");
do
{
opcion=toupper(getch());
}
while((opcion!='S')&&(opcion!='N'));
putchar(opcion);
if (opcion=='S')
backup();
gotoxy(1,25);
textcolor(WHITE);
delline();
gotoxy(1,25);
cprintf("Por favor, pulse una tecla para continuar ...");
getch();
return 0;
}
else
{
if (mayuscula=='N')
{
return 0;
}
}
}
while ((mayuscula!='S')&&(mayuscula!='N'));
}
Nunca aparace la primera persona, con lo que borra la que no es. ¿Donde está
el error?
Gracias anticipadas.
****************************************************************************
*
* FUNCION BORRAR
*
****************************************************************************
****
*/
int borrar (int*r)
{
int i,del;
int opcion;
int mayuscula;
*r=cuenta_personas;
if (*r==0)
{
clrscr();
gotoxy(28,12);
cprintf("LA AGENDA ESTA VACIA");
getch();
return 1;
}
clrscr();
gotoxy(14,12);
cprintf("INTRODUCIR EL NUMERO DE PERSONA QUE DESEAS BORRAR : ");
textcolor(RED);
textbackground(WHITE);
scanf("%d",&del);
for(i=del;i<*r;i++)
{
cprintf("nn 255255255 A T E N C
I O N !!! ");
textcolor(30);
textbackground(BLACK);
cprintf("nr Se va a borrar la persona con indice %d: 256
%s %s %s 257
",i,datos[i-1].nombre,datos[i-1].primer_apellido,datos[i-1].segundo_apellido
);
gotoxy(19,18);
textcolor(WHITE);
textbackground(BLACK);
cprintf("n250Est240 seguro de querer continuar? (S/N): ");
do
{
opcion=getchar();
mayuscula=toupper(opcion);
if (mayuscula=='S')
{
strcpy(datos[i].nombre,datos[i+1].nombre);
strcpy(datos[i].primer_apellido,datos[i+1].primer_apellido);
strcpy(datos[i].segundo_apellido,datos[i+1].segundo_apellido);
strcpy(datos[i].direccion,datos[i+1].direccion);
strcpy(datos[i].telefono,datos[i+1].telefono);
strcpy(datos[i].movil,datos[i+1].movil);
*r=*r-1;
cuenta_personas=cuenta_personas-1;
gotoxy(20,19);
textbackground(GREEN);
cprintf("nSe ha borrado la persona con indice %d",i);
gotoxy(1,25);
cprintf("250Deseas actualizar el archivo de disco? (S/N): ");
do
{
opcion=toupper(getch());
}
while((opcion!='S')&&(opcion!='N'));
putchar(opcion);
if (opcion=='S')
backup();
gotoxy(1,25);
textcolor(WHITE);
delline();
gotoxy(1,25);
cprintf("Por favor, pulse una tecla para continuar ...");
getch();
return 0;
}
else
{
if (mayuscula=='N')
{
return 0;
}
}
}
while ((mayuscula!='S')&&(mayuscula!='N'));
}
