So far i got new patient and show_queue (working).
I got a little doubt
When i make malloc should i put the patient i just create to NULL or that don΄t matter ?
Code:
// 1Ί Get Memory from the new patient, and putting the block to NULL
if ((new_patient = malloc(sizeof (node))) == NULL) {
printf("Something went wrong -> %s\n", strerror(errno));
return list;
}
new_patient->next = NULL; // Put the NULL the patient i just create
Full Functions
Code:
node * new_patient(node * list) {
node * new_patient;
node * aux;
// 1Ί Get Memory from the new patient, and putting the block to NULL
if ((new_patient = malloc(sizeof (node))) == NULL) {
printf("Something went wrong -> %s\n", strerror(errno));
return list;
}
new_patient->next = NULL; // Put the NULL the patient i just create
// 2Ί Getting the input from the user
puts("What is the name of the new patient ?");
scanf(" %[^\n]", new_patient->name);
// 3Ί Insert on the list
if (list == NULL) {
list = new_patient;
} else {
aux = list;
// Going to run the list until i reach the end.
while (aux->next != NULL) {
aux = aux->next;
}
// Put the last one pointing to the new block
aux->next = new_patient;
}
return list;
}
void show_queue(node * list) {
if (list == NULL) {
printf("The list is empry\n");
} else {
while (list != NULL) {
printf("The name of the patient is %s\n", list->name);
list = list->next;
}
}
}
The rest of the work is on progress.