I have a linked list Student
struct Student
{
char name[20];
char Class[20];
string reg;
float cgpa;
int marks;
Student *next;
}*head,*lastptr;
What i want to do is to search a Student by a name
here is my searchStudent function which is not working dont know what is the issue..
Student searchStudent(){
cout << "1. Search By Name" << endl;
cout << "2. Lower Then CGPA" << endl;
cout << "3. Equal To CGPA" << endl;
cout << "4. Greater than CGPA " << endl;
cout << "5. By Program " << endl;
cout << "6. Exit" << endl;
cout << endl;
char choice;
cin >> choice;
if(choice == '1'){
cout << endl;
char *name;
cout << "You chose option #1." << endl;
cout<<"Please enter name you want to search: " <<endl;
cin>>name;
cout << endl << "Listing all student Students : " << endl;
cout << "-----------------------" << endl;
Student *current;
current = head;
if (current->next == NULL) //Reached end of the list
{
cout<<"\n name not found in the Linked List \n";
}
while(current != NULL)
{
cout<<name[20];
cout<<current->name;
if (strcmp(current->name, name) == 0) { //found the element
cout << current -> name << endl;
cout << current -> Class << endl;
cout << current -> reg << endl;
cout << current -> cgpa << endl;
cout << current -> marks << endl;
current = current -> next;
cout << endl;
} else { //search next element
return searchStudent(); //this will call your function again for the next element on the list
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire