我有2个问题..
对 a 执行以下命令时是否需要添加终止字符
char *string
?strcpy();
strncpy();
是否有必要在执行上述任何操作之前分配内存以针对
char *string
?
例如..
char *str;
str = malloc(strlen(texttocopy));
strcpy(texttocopy, str); // see the below edit
请解释。
编辑: 在上面的代码中,我倒置了参数。这只是我在这里问问题时犯的错字。正确的方法应该是
strcpy(str, texttocopy); // :)