我可以使用malloc
并strcpy
替换它吗?哪一个更好?
例如:
char *s = "Global View";
char *d;
d = strdup(s);
free(d);
Run Code Online (Sandbox Code Playgroud)
要么
char *s = "Global View";
char *d = malloc(strlen(s) +1);
strcpy(d,s);
free(d);
Run Code Online (Sandbox Code Playgroud) c ×1