const char* conversion

The problem is that when a function receives a pointer as a parameter, the function has no context to the length of the object that the pointer "points to". In this case, sizeof(ptr); will simply return the byte length of ptr itself, not what it points to.

When passing a pointer to a function, you should also send the length of the object as another parameter. This is why, for example, you'll see functions like this in C++:

/* using memcpy to copy structure: */
memcpy ( &person_copy, &person, sizeof(person) );