I am facing a problem and I tried to debug it but I couldn't find anything
#include <stdio.h>
#include <stdlib.h>
struct Process {
int id;
int at;
int bt;
int rt;
struct Process *next;
} *tmp;
struct Queue {
struct Process *head, *tail;
};
struct Process *pop(struct Queue *queue) {
if (queue->head == NULL) {
return NULL;
}
tmp = queue->head;
queue->head = queue->head->next;
return tmp;
}
int main() {
struct Queue queues[3];
struct Process *working;
for (int i = 0; i < 3; i++) {
queues[i].head = NULL;
}
FILE *processesFile = fopen("processes.txt", "r");
while (!feof(processesFile)) {
fscanf(processesFile, "%d %d %d", &id, &at, &bt);
push(&queues[0], id, at, bt);
}
working = pop(&queues[0]); // HERE IS THE PROBLEM, It is removing the first element but causing segmentation error
return 0;
}
I removed the pushing part, I could successfully push 5 values and print the whole queue without any problems