In the code below you allocate too much memory:
str = malloc((strlen(str)+1)*sizeof(DString));//mycode
^^^^^^^^^^^^^^
Not needed
Also you assign the return value from malloc
to the input argument, i.e. you "destroy" the input.
Further, you never copy the value of the input string to the allocated memory.
Instead of the above, you need:
char* res = malloc(strlen(str) + 1);
if (res != NULL)
{
strcpy(res, str);
}
return res;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…