assignment to expression with array type

1

I'm having an error while associating an array address in a pointer to struct, I'm getting an error of type:

  

assignment to expression with array type

The code I'm using is this:

struct MaxHeap
{
    int size;
    int* array;
};

struct MaxHeap* createAndBuildHeap(char array[][25], int size)
    int i;
    struct MaxHeap* maxHeap =
          (struct MaxHeap*) malloc(sizeof(struct MaxHeap));
    maxHeap->size = size;   // initialize size of heap
    maxHeap->array = array; // Assign address of first element of array

    // Start from bottommost and rightmost internal mode and heapify all
    // internal modes in bottom up way
    for (i = (maxHeap->size - 2) / 2; i >= 0; --i)
        maxHeapify(maxHeap, i);
    return maxHeap;
    
asked by anonymous 14.10.2017 / 16:17

2 answers

0

When you try to pass the array to the new allocated structure:

maxHeap->array = array; // Assign address of first element of array

The type of maxHeap->array does not play with the type of array of the function.

Now notice the two closely:

struct MaxHeap
{
    int size;
    int* array;
};//^
//  ^ int* aqui --------------------------- char[][] aqui 
//                                        v
struct MaxHeap* createAndBuildHeap(char array[][25], int size)

In other words, you are trying to put char[][] into int* .

For what you indicated in the comments, you want to use the heap for names, then you should change the structure of it to char ** , the appropriate type for this:

struct MaxHeap
{
    int size;
    char **array; //agora o tipo correto para os nomes
};
    
14.10.2017 / 17:25
0

EDIT 1

struct MaxHeap
{
    int size;
    int* array;
};

struct MaxHeap* createAndBuildHeap(char array[][25], int size)
int i;
struct MaxHeap* maxHeap =
          (struct MaxHeap*) malloc(sizeof(struct MaxHeap));
maxHeap->size = size;   // initialize size of heap
maxHeap->array = array; // Assign address of first element of array

// Start from bottommost and rightmost internal mode and heapify all
// internal modes in bottom up way
for (i = (maxHeap->size - 2) / 2; i >= 0; --i)
    maxHeapify(maxHeap, i);
return maxHeap;
    
14.10.2017 / 16:56