char* temp;
temp = (char*) malloc (strlen(window->entry.value)+1);
//strncpy( temp, window->entry.value, sizeof(temp) ); DOESN"T WORK
memcpy (temp, window->entry.value, strlen(window->entry.value) + 1); //WORKS
(where window->entry.value is a string.)
Thanks.
sizeof(temp)doesn’t do what you think it does. It tells you the size, in bytes, of a pointer to char, which is whattempis. Most likely on your system either 4 or 8.This has nothing to do with the length of any particular string, or the size of any particular buffer returned from
malloc.It’s pure fluke that you’ve passed the right length when using
memcpy, and the wrong length when usingstrncpy.memcpywould also not work if passedsizeof(temp)as the length, andstrncpywould work if passed the right length.