I practically have to modify the field .baja
of the structure of Cliente
(this if it is modified correctly) and it turns out that all the other fields are also modified but with junk content. The idea is that they contain the same thing they had before but only changing the clienteBaja.baja
. Thanks
int buscaCliente(FILE*archi)
{
Cliente clientes;
int buscar=0;
int posicion=-1;
if(archi!=NULL)
{
printf("Ingrese el D.N.I. de un cliente a buscar\n");
scanf("%i", &buscar);
while(fread(&clientes,sizeof(Cliente),1,archi)>0)
{
if(buscar==clientes.dni)
{
posicion=ftell(archi)/sizeof(Cliente);
}
}
}
return posicion;
}
void bajaCliente()
{
Cliente clienteBaja;
int posicion;
FILE*archi=fopen("cliente","r+b");
posicion=buscaCliente(archi);
if(posicion==(-1))
{
printf("El cliente no existe");
}
else
{
fseek(archi,(posicion-1)*(sizeof(Cliente)),SEEK_SET);
clienteBaja.baja='s';
fseek(archi,sizeof(Cliente),SEEK_CUR);
}
fwrite(&clienteBaja,sizeof(Cliente),1,archi);
fclose(archi);
}