juice juice - 1 year ago 56
C Question

How to use enum in C

Basically we have to implement a queue (linked list) for a restaurant waiting queue.

We get extra points for using

enum
but I've never used it before. I'm wondering does this look right how I am using it? I have looked it up but haven't seen any examples using linked lists.

Here is the instructions for our structure:


When writing your code, you MUST create a C struct for the nodes in the linked list of the wait list. These data items must include the following (and may include others if needed).


  • the name of the group

  • the integer variable specifying the size of the group (number of people in the group)

  • the in-restaurant status (extra points for using an enum!)

  • a pointer to the next node in the list



The restaurant status is walk-in or call-in (call ahead of time to put name on waiting list)


Here's the structure of mine:

typedef struct restaurant
{
char name[30];
int groupSize;
enum status{call, wait};
struct restaurant *nextNode;
}list;


I'm asking because I get this warning when I compile:


lab6.c:11:28: warning: declaration does not declare anything [enabled by default]


Answer Source

Your struct typedef is basically saying "If I had a "status" field in my record, it could have the value "call" or the value "wait". The warning is basically saying "you never allocated a field".

Possible change:

enum status {CALL, WAIT};

typedef struct restaurant
{
    char name[30];
    int groupSize;
    enum status my_status;
    struct restaurant *nextNode;
}list;

Here's more info: