Search code examples
cstringerror-handlingrealloc

How to do type casting for the below expression


I am trying to reallocate memory to my table using the below expression.But I always keep getting the below error.Please kindly advise me.

typedef char *OFAttribs[6];
 OFAttribs *tmp = realloc(pTable, sizeof(*tmp) * (nTableLen+1));

Error: invalid conversion from âvoid*â to âchar* (*)[6]â

Solution

  • Try this:

    OFAttribs *tmp = (OFAttribs*) realloc(pTable, sizeof(*tmp) * (nTableLen+1));