Oosutsuke Oosutsuke - 3 years ago 291
C Question

Expression must be a pointer to a complete object type when cast void pointer

I'm trying to do function remove extension of a name is type wchar_t or char, inside for() i cast void pointer to type wchar_t or char, then there was an error:


Expression must be a pointer to a complete object type.


Here is sample code to show an instance of the issue by itself.

int RemoveExtension(
void *p_str, /* Name */
bool isWchar /* true:wchar_t, false:char */
) {
int ii, len;

// Get length
len = (isWchar) ? wcslen( (wchar_t *)p_str ) : strlen( (char *)p_str );

// Remove extension
/* wchar_t */
if( isWchar ) {

for( ii = 0; ii < len; ii++ ) {
if( L'.' == (wchar_t *)p_str[ii] ) { //Error here
(wchar_t *)p_str[ii] = L'\0'; //Error here
break;
}
}
}
/* char */
else {

for( ii = 0; ii < len; ii++ ) {
if( '.' == (char *)p_str[ii]) { //Error here
(char *)p_str[ii] = '\0'; //Error here
break;
}
}
}

return 0;
}


I'm not understanding what this error is trying to say. There is no object or struct here.

Answer Source

I dont know why you get exactly that error, but according to this table expression

(wchar_t *)p_str[ii] is (wchar_t *)(p_str[ii])

not ((wchar_t *)p_str)[ii],

probably it's not what you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download