-2
struct nodePatient {
    struct Patient * patient; 
    struct nodePatient * next;
};

struct linkedQueue {
    struct nodePatient * firstNode;
    struct nodePatient * lastNode;
    unsigned size;
    unsigned maxSize;
};


struct PriorityQueue {
    struct linkedQueue * queue;
    int size;
    unsigned minPriorityValue;
};



struct PriorityQueue * createPriorityQueue(unsigned minPriorityValue) {
    struct PriorityQueue * newPriorityQueue = (struct PriorityQueue*) malloc (sizeof (struct PriorityQueue));
    newPriorityQueue->queue = (struct linkedQueue*) calloc (minPriorityValue+1, sizeof (struct linkedQueue));
    int i;

    newPriorityQueue->minPriorityValue = minPriorityValue;
    for(i = 0; i < minPriorityValue; i++) {
        newPriorityQueue->(queue+i)->maxSize = UNLIMITED_SIZE;
        newPriorityQueue->(queue+i)->size = 0;
        newPriorityQueue->(queue+i)->firstNode = NULL;
        newPriorityQueue->(queue+i)->lastNode = NULL;
    } 
    return newPriorityQueue;    
}

This is a part of my code and when i'm trying to compile i'm getting the fallowing errors:

What is it wrong in it?

sebenalern
  • 2,515
  • 3
  • 26
  • 36
MeNpHiS
  • 1
  • 1
  • 4
    Welcome to Stack Overflow! [Please see this discussion on why not to cast the return value of `malloc()` and family in `C`.](http://stackoverflow.com/q/605845/2173917). – Sourav Ghosh Apr 26 '16 at 14:30
  • Just saying, `newPriorityQueue->(queue+i)->maxSize` is a pretty weird way to write a meaningful and understandable code. – Sourav Ghosh Apr 26 '16 at 14:32
  • 1
    You could do `(newPriorityQueue->queue+i)->maxSize = ...`. Not pretty, but should work. The traditional way would be `newPriorityQueue->queue[i].maxSize = ...`. – EOF Apr 26 '16 at 14:39
  • You are expoected to post text as text, not links or images. – too honest for this site Apr 26 '16 at 14:58
  • "*i'm getting the fallowing errors: enter image description here*" so what keeps you from entering an image description though? – alk Apr 26 '16 at 16:12

1 Answers1

1

The expression

newPriorityQueue->(queue+i)

is wrong given your object types. Due to operator precedence (queue+i) is evaluated first. However, queue is not an independent variable. It is a member of the struct.

Hence, you need to use:

(newPriorityQueue->queue+i)

A syntactically correct line would be:

(newPriorityQueue->queue+i)->maxSize = UNLIMITED_SIZE;

You could make it more readable by using:

newPriorityQueue->queue[i].maxSize = UNLIMITED_SIZE;
R Sahu
  • 204,454
  • 14
  • 159
  • 270