/* Data structure for Vector */
typedefstruct
{
void* pvElement; /* the pointer to elements */
size_t iSizeElement;/* the size of element */
int iNumElement; /* the number of elements (user's view) */
int iNumAlloc; /* the number of allocated elements (system's view) */
} Vector;
/* error C2036: 'void *' : unknown size occurs in line 12th */
for (i = 0; i <= (v->iNumElement) - 1; i++)
memcpy((char*)&(newV->pvElement[i]), (char*)&(v->pvElement[i]), (size_t)v->iSizeElement);
You cannot use [] in a pointer of type void* because the size of the element pointed to by the pointer is unknown. You must cast the pointer pvElement into a data type before attempting this.
So yes, ((char*)v->pvElement)[i] works but that is not all. i is not the ith element, but the ith byte. You need to do ((char*)v->pvElement)[i * v->iSizeElement] to really get a pointer to the first byte of the ith element.
What I want to say is that to move x consective elements is a loop like this is pretty naff.
He knows the size of the element - so to move x consecutive elements: