#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
struct node{
int num,ages;
string name,skills;
struct node *link;
};
typedef struct node *nodepointer;
nodepointer add(nodepointer &head, int nu, int age);
void str(nodepointer &head, string na, string ski);
void DeleteFront(nodepointer &head);
void display(nodepointer head);
int main(){
nodepointer head = NULL;
int c,nu,age;
string na,ski;
do{
up:
system("CLS");
cout<<"[1]Add wizard"<<endl;
cout<<"[2]Delete wizard"<<endl;
cout<<"[3]Search wizard"<<endl;
cout<<"[4]Display wizard"<<endl;
cout<<"[5]Exit"<<endl;
cout<<"Choose from numbers 1-5"<<endl;
cin>>c;
switch(c)
{
case 1:
cout<<"Enter number: "<<endl;
cin>>nu;
head = add(head,nu,age);
cout<<"Enter age: "<<endl;
cin>>age;
head = add(head,nu,age);
cout<<"Enter name: "<<endl;
cin>>na;
str(head,na,ski);
cout<<"Enter skill: "<<endl;
cin>>ski;
goto up;
getch();
break;
case 2:
DeleteFront(head);
getch();
break;
case 3:
getch();
break;
case 4:
display(head);
getch();
break;
case 5:
exit(1);
break;
}
}while (c!=0);
getch();
}
nodepointer add(nodepointer &head, int nu, int age)
{
nodepointer newnode;
newnode=(nodepointer)malloc(sizeof(struct node));
newnode->num=nu;
newnode->ages=age;
newnode->link=head;
head=newnode;
}
void str(nodepointer &head, string na, string ski)
{
nodepointer newnode;
newnode=(nodepointer)malloc(sizeof(struct node));
newnode->name=na;
newnode->skills=ski;
newnode->link=head;
head=newnode;
}
void DeleteFront(nodepointer &head)
{
nodepointer temp;
if (head == NULL)
printf("Linked list is empty…");
else
{
temp = head;
head = head -> link;
free(temp);
}
}
void display(nodepointer head)
{
if(head==NULL)
{
printf("\n no data");
}
else
{
while(head->link!=NULL)
{
printf("Number: %i",head->num);
printf("\nAge: %i",head->ages);
printf("\nName: %s",head->name);
head=head->link;
}
}
}
can somebody what im doing wrong here?
if i only used numbers in linked list there are no errors but if started using string i just cant get it to work
can somebody help me?