Hey guys, trying to create a program which add/store records of patients to a node using doubly linked list. When the program executes, I'm only able to create one record. The program doesn't allow me add anymore patient and when I tried to display the record the program output different characters to the screen instead of the record.
Code:
#define STRING_MAX 40
typedef struct Patient{
char patientName[STRING_MAX];
int patientAge;
int patientRegion;
struct Patient *prev;
struct Patient *next;
}Patient;
struct Patient *head, *tail = NULL;
struct Patient *current = NULL;
void addPatient()
{ char *patientName;
int patientAge;
int patientRegion;
struct Patient *patient = (Patient *)malloc(sizeof(Patient));
strncpy(patient->patientName,patientName,STRING_MAX);
patient->patientAge = patientAge;
patient->patientRegion = patientRegion;
patient->prev = NULL;
patient->next = NULL;
if(head == NULL){//if head node is null, then get user input to create a record
printf("Enter patient Name: \n");
scanf("%s", patientName);
printf("Enter patient Age: \n");
scanf("%d", &patientAge);
printf("Enter patient Region: \n");
scanf("%d", &patientRegion);
while(patientRegion > 10) //If the region is greater than ten, prompt user to enter a number less than 10
{
printf("Invalid region\n");
printf("Please enter region between (1 - 10): ");
scanf("%d", &patientRegion);
}
head = patient;
return;
}
}
void displayPatient(){
struct Patient *current = head;
if(head == NULL) {
printf("\nList is empty\n\n");
return;
}
printf("Patient Records: \n");
while(current != NULL) {
printf("%s", current->patientName);
printf("%d", current->patientAge);
printf("%d", current->patientRegion);
current = current->next;
}
}