vendredi 12 novembre 2021

How to check if the first entry of an array of entries is empty when the array is of type struct in C?

I have to write a Program for Uni in which there is supposed to be a queue with a priority and in the queue there is supposed to be an array of entries of which each entry needs to be 31 characters. Also there needs to be a function that checks if the queue is empty or full. I have written this code but it doesnt work, I get the error invalid oprands to binary == (have entry and 'int'):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

enum priority {
    H, h, n, l, L      //Priority enum Highest = 0 Lowest = 4
};

typedef struct entry{
    enum priority priorityvar;
    char message[31];
} entry;

typedef struct pqueue {
    entry entries[10];
} pqueue;

int isEmpty(pqueue* pqueue){
    if (pqueue->entries[0] == 0)
        return 1;
    else
        return 0;
}
int isFull(pqueue* pqueue){
    if (pqueue->entries[9] != 0)
        return 1;
    else
        return 0;
}

I also tried to replace the 0 with a NULL but that didnt work either, I would be so grateful for any help! Thank you so much!!

Ps: I also have to write a function later in which the first entry is being printed and deleted while all the other etries move 1 "up" in the queue and I have no Idea how to implement that. If somebody has ideas thank you so much!!

Aucun commentaire:

Enregistrer un commentaire