I try to delete a contact but regardless of the line that I indicated to delete only delete the line 0
void borrarContacto ()
{
int l, linea, NUMlineas=0;
char LINEA[MAX],c, ch;
FILE *destino, *a;
printf ("\nTu lista de contactos es la siguiente: \n");
mostrarContactos();
printf ("Introduce el numero de contacto que quieres borrar (linea): ");
scanf ("%d", &l);
system("PAUSE");
a=fopen ("E:\datos.dat", "r+");
destino=fopen ("E:\datos2.dat", "w+");
/*Leemos todas las lineas del archivo*/
while (fgets (LINEA, MAX, a)!=NULL)
{
if ((ch=getc(a))!= EOF)
ungetc(ch, a);
NUMlineas++;
if (NUMlineas!=linea)
{
fputs(LINEA, destino);
}
}
printf ("\nEl contacto ha sido eliminado. Revise su archivo.\n");
fclose(a);
fclose(destino);
remove ("E:\datos.dat");
rename ("E:\datos2.dat", "E:\datos.dat");
}