C++在一个函数中定义一char数组,想调用另一个函数对其赋值,然后在原函数中用,该怎么办?

来源:百度知道 编辑:UC知道 时间:2024/05/27 15:31:27

把那个char指针传过去,然后用strcpy(str,"this is the string to copy")
还是举个简单的例子吧:
#include <string.h>
#include <stdio.h>
void test(char str[])
{
char mystr[20]="我的字符串";
strcpy(str,mystr);
}

int main(void)
{
char str[20];
test(str);
printf("now the string value is %s\n",str);
return 0;
}

直接用strcpy函数呀,干嘛那么麻烦