Comment Comment by userbinator Even simpler, you can do something like this to have length-delimited AND null-terminated strings (written from memory, no guarantees of correctness etc.): char *lenstrdup(char *s) { int n = strlen(s); char *p = malloc(n + sizeof(int) + 1); if(p) { strcpy(p + sizeof(int), s); *(int*)p = n; p += sizeof(int); } return p; } void lenstrfree(char *s) { free(s-sizeof(int)); } parent userbinator 9 months ago