I'm basically trying to create a linked list / queue out of the data in a struct array, but it refuses to work.
Here's the code, tried allocating memory to front but to no avail, the output is just the while loop infinitely looping.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{
char ID[12];
long arrtime;
double priority;
struct node *next;
} request;
void main()
{
request *front;
request *rear;
request *new = (request *)malloc(sizeof(request));
request *arr = (request *)malloc(100 * sizeof(request));
for (int k = 0; k < 4; k++)
{
printf("ID:: ");
scanf("%s", arr[k].ID);
printf("Arrival time:: ");
scanf("%ld", &arr[k].arrtime);
printf("Priority::");
scanf("%lf", &arr[k].priority);
}
for (int k = 0; k < 4; k++)
{ printf("\n %s %ld %lf\n", arr[k].ID, arr[k].arrtime, arr[k].priority);
}
strcpy(new->ID, arr[0].ID);
new->arrtime = arr[0].arrtime;
new->priority = arr[0].priority;
front = new;
rear = front;
for (int i = 1; i < 4; i++)
{
strcpy(new->ID, arr[i].ID);
new->arrtime = arr[i].arrtime;
new->priority = arr[i].priority;
rear->next = new;
rear = new;
}
// print test!!
request *walker = front;
printf("\n............QUEUE CONTENT.........\n");
while (walker != NULL)
{
printf("\n%s %ld %.1lf\n", walker->ID, walker->arrtime, walker->priority);
walker = walker->next;
}
return;
}