I need to search elements of a stack and a linked list. I implemented stack using linked list I have search both function to do it.
Code:
struct student{
char name[100];
char surname[100];
char roll[10];
char department[50];
struct student *next;
};
struct theStack{
struct student *head;
struct student *pop;
struct student st;
};
struct theStack myStack;
void search_both(){
struct student *a;
struct theStack *x;
a=(struct student*)malloc(sizeof *a);
x=(struct theStack*)malloc(sizeof *x);
while(strcmp(a->name, x->st.name)==0){
while(strcmp (a->surname, x->st.surname)==0){
printf("%s %s and %s %s taking both classes",a->name, a->surname,x->st.name,x->st.surname);
a=a->next;
x=x->st.next;
}
}
free(a);
free(x);
}
what must be the wrong part of my code?