I have this structure:
struct Alumno{
string nombre;
long ci;
char sexo;
int edad;
string direccion;
long telefono;
Alumno*siguiente;
};
Alumno*listaAlumno=NULL;
and with this function I create my students (before saying that it is a list, but thanks to a user I point out that a node that points to another is not a list, so we will call it an array of linked dynamic structures):
void insertarAlumno(Alumno*&listaAlumno){//le paso la referencia & para poder agregar elementos a la lista
long cedula;
//arreglo dinamico
Alumno*nuevo_Alumno=new Alumno();
fflush(stdin);
cout<<"Ingrese Nombre y Apellido: ";
getline(cin,nuevo_Alumno->nombre);
fflush(stdin);
cout<<"Ingrese Cedula: ";
cin>>cedula;
nuevo_Alumno->ci=cedula;
fflush(stdin);
cout<<"Ingrese sexo(M,F): ";
cin>>nuevo_Alumno->sexo;
fflush(stdin);
cout<<"ingrese edad: ";
cin>>nuevo_Alumno->edad;
fflush(stdin);
cout<<"ingrese Direccion: ";
getline(cin,nuevo_Alumno->direccion);
fflush(stdin);
cout<<"ingrese telefono: ";
cin>>nuevo_Alumno->telefono;
fflush(stdin);
//variables auxiliares para colocar el nodo al principio en medio o al final
Alumno*aux1=listaAlumno;
Alumno*aux2;
//ordenamiento.. si la cedula ingresada es mayor el nuevo nodo se intercambiara posiciones hasta ponerse adelante
while((aux1 != NULL)&&(aux1->ci < cedula)){
aux2=aux1;//aux2 se intercambiaria con el primero
aux1=aux1->siguiente;//y aux1 estaria apuntando al siguiente elemento de la lista
}
//se cumple si el nuevo nodo va al principio de la lista
if(listaAlumno==aux1){
listaAlumno=nuevo_Alumno;
}
//si no se cumple quiere decir que entro al ordenamiento
else{
aux2->siguiente=nuevo_Alumno;
}
//en todo caso el *siguiente de la estructura para llevar el la lista nodo->nodo->nodo
nuevo_Alumno->siguiente=aux1;
cout<<"\tTodos los datos del estudiante "<<nuevo_Alumno->nombre<<" Han sido registrados"<<endl;
system("pause");
}
Now where is my problem? ... if I remove all the data below it ... the function works fine .. but if I add that bit of data the buffer becomes all crazy and even cleaning the buffer I fix the problem ( see that you fill in the fflush algorithm) .. what is happening to me? When I'm going to put the last phone number will not let me enter it .. and proceed to register the student and return to main the program automatically enters the student register and enters a cycle where he does not let me do anything, as I said before I only register the name and the identity card the program works well for me ... the problem is to get that amount of data ... I do not want to imagine when you start working with student-teacher-subject relations