Tried looking at past questions dealing with this issue but all of those seem to relate to C++ not C. And I have to write the program in C. So I have this portion of code that is suppose to do the following: Modifies an existing kstring, pointed to by strp, to be at least nbytes bytes long... And so on. But I have the code for the function but I keep getting an error: invalid conversion from ‘void*’ to ‘char*’.
typedef struct
{
char *data;
size_t length;
} kstring;
Function:
void kstrextend(kstring *strp, size_t nbytes)
{
char *nwData;
int lnth=strp->length;
if(lnth < nbytes)
{
// new array allocate with large size and copy data to new array
nwData = realloc(strp->data, nbytes);
// call abort in case of error
if(nwData == NULL)
{
abort();
}
//Making strp->data point to the new array
strp->data = nwData;
//Setting strp->length to the new size.
strp->length = nbytes;
// filled with '\0' in remaining space of new array
for (int lp = lnth; lp < nbytes; lp++)
{
strp->data[lp] = '\0';
}
}
}
Portion of main where function is called:
name.data = (char*)calloc(sizeof("Hello"), 1);
strcpy(input, "Hello");
name.length=5;
kstrextend(&name,40);
printf("%s %d",name.data,name.length);