0

I am using visual studio for C, where I am making an array of Nodes containing int datatypes (startCount and endCount) from a doubly linked list. So I am inserting the nodes from a d-linked list into this array. Then I am trying to sort it by partitioning it. And I get the following errors:

left of '->startCount' must point to struct union
expression must have pointer-to-class type

for the following code in the while statement:

int PartitionArray(DListNode*** sortArray){
........
while((*sortArray[left]->startCount - *sortArray[left]->endCount) < (pivot->startCount - pivot->endCount)){
left++;
}
........
}

where in main I have:
int main(){
DListNode **sortArray;
PartitionArray(sortArray);
}

I don't understand how I am suppose to access the values of the nodes through the array passed by reference.

1 Answer 1

1

Depending on how you have defined your data structures, you may be dereferencing the variables the wrong way. As the * operator has a lower precedence, you may need to use

(*sortArray)[left]->startCount 

or

(*sortArray[left])->startCount 

or

(*sortArray)[left].startCount 

or

(*sortArray[left]).startCount 

instead of

*sortArray[left]->startCount
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Now I have another question: I am getting a segmentation fault when I set an element in sortArray to a pointer to a node inside the funciton: int PartitionArray(DListNode*** sortArray){ DList Node = curNode; sortArray[1] = curNode; } I get a segmentation fault.
It seems that sortArray may not have been initialized. I would need to see the code before calling PartitionArray() to understand how the data structures are being handled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.