Question: I need to ask the user to input information about a person. the name, age(, height, and the birthdate. After I get the information I
I need to ask the user to input information about a person. the name, age(, height, and the birthdate.
After I get the information I need, I store the information through the struct variables. However, I have a problem with putting all the information into one node and calling the function.
here's the full program in a .zip file http://www.filedropper.com/untitled_86
here are the structures
typedef char NAME[41]; typedef struct date { int month; int day; int year; } DATE; typedef struct person { NAME name; int age; float height; DATE bday; } PERSON; typedef struct list { void *data; struct list *next; } LIST; here is the part of the main method that is relevant to the problem
int main(void) { PERSON *person; int num; puts("Enter the initial number of records:"); if (scanf("%d", &num) < 1) num = DEF_NUM; while (num-- > 0) { person = (PERSON *) malloc(sizeof(PERSON)); inputPersonalData(person); addPersonalDataToDatabase(person); }
here's the method where I ask the user input
LIST *head = NULL, *tail = NULL; void inputPersonalData(PERSON *person) { printf("enter the name"); scanf("%s", person->name); printf("enter the age"); scanf("%d", &person->age); printf("enter the height"); scanf("%f", &person->height); printf("enter the birthdate"); scanf("%d/%d/%d", &person->bday.month, &person->bday.day, &person->bday.year); printf("%s %d %f %d %d %d", person->name, person->age, person->height, person->bday.month, person->bday.day, person->bday.year); /*head->data = &person->name; printf("%p", head->data);*/ } void addPersonalDataToDatabase(PERSON *person) { // add(head, tail, person); // need help here once I call the function add it always leaves // with exit code 11 }
linked list function
void add(LIST **head, LIST **tail, void *data) { if (*tail == NULL) { *head = *tail = (LIST *) malloc(sizeof(LIST)); (*head)->data = data; (*head)->next = NULL; } else { (*tail)->next = (LIST *) malloc(sizeof(LIST)); *tail = (*tail)->next; (*tail)->data = data; (*tail)->next = NULL; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
