The most detailed problem is that when I enter a new student I save it, I look for it and it shows it, but as soon as I enter the second student onwards he throws "Error: DNI Incorrect." Touch any button to return to the previous menu " I do not know if it keeps a single student or when I look for the second one on it does not search. I leave below code where I enter student and I am looking for students
struct Alumno
{
char apellido[50];
char nombre[50];
int dni;
int legajo;
};
int Ingresar_Alumno (int &e)
{
FILE *cho;
Alumno vectoralumno[TOTAL];
if (cho=fopen("cho.dat", "wb+"))
{
cout << "ingrese el nombre del alumno: ";
cin >> vectoralumno[e].nombre;
cout << "ingrese el apellido del alumno: ";
cin >> vectoralumno[e].apellido;
cout << "ingrese legajo del alumno: ";
cin >> vectoralumno[e].legajo;
cout << "ingrese el DNI del alumno: ";
cin >> vectoralumno[e].dni;
fwrite(vectoralumno,sizeof(struct Alumno),1,cho);
}
fclose(cho);
e++;
}
void BuscarDNI(int dni, int &q)
{
Alumno dchof;
FILE *x;
if(x=fopen("cho.dat","rb"))
{
while ( true )
{
fread(&dchof,sizeof(struct Alumno),1,x);
if( feof(x) )
break;
if(dni == (dchof.dni))
{
cout << "El alumno buscado es: " << endl;
cout << "Nombre: " << dchof.nombre << endl;
cout << "Apellido: " << dchof.apellido << endl;
cout << "Legajo: " << dchof.legajo << endl;
cout << "DNI: " << dchof.dni << endl;
cout<< "Toque cualquier boton para volver al menu anterior" << endl;
getch();
}
}
if(dni!=dchof.dni)
{
cout<< "Error: DNI Incorrecto" << endl;
cout<< "Toque cualquier boton para volver al menu anterior" << endl;
getch();
}
}
fclose(x);
}