I'm doing a function that reads a series of elements from a binary file and I have to pass them to another file that organizes them into cubes using the hash dispersion method. Here's the function:
int creaHash(char *fichEntrada,char *fichHash){
FILE *f;
FILE *fHash;
tipoAlumno alumno;
tipoCubo cubo;
int i = 0, registro, dni;
int numCubos =CUBOS+CUBOSDESBORDE;
creaHvacio(fichHash);
f = fopen(fichEntrada, "rb");
fHash = fopen(fichHash, "r+b");
while(!feof(f)){
fread(&alumno, sizeof(tipoAlumno), 1, f);
registro = atoi(alumno.dni) % CUBOS;
//Buscamos el numero de cubo correspondiente
fseek(fHash, registro*sizeof(tipoCubo), SEEK_SET);
fread(&cubo, sizeof(tipoCubo), 1, fHash);
if(cubo.numRegAsignados <= C){ //Podemos escribir en el cubo porque no está lleno
fseek(fHash, registro*sizeof(tipoCubo), SEEK_SET);
fwrite(&cubo, sizeof(tipoCubo), 1, fHash);
cubo.numRegAsignados++;
}
else{
//cubo desbordado
}
}
fclose(f);
fclose(fHash);
tipoAlumno
and tipoCubo
are two structures. The function would work like this:
fichEntrada
and for each entry, I get a number making a atoi
of the dni. fseek
. fichEntrada
and increase the numeroRefAsignados
. But he does not write anything. Something I'm leaving that I can not find. Thanks for the help!