在C语言中,可以使用strcpy()函数将字符串赋值给变量。例如:
#include <stdio.h>
#include <string.h>
int main() {
char str1[20];
char str2[] = "Hello, World!";
strcpy(str1, str2);
printf("str1: %s\n", str1);
return 0;
}
上面的代码中,我们首先定义了两个字符数组str1和str2,然后使用strcpy()函数将str2中的字符串赋值给str1,最后打印输出str1的值。运行结果为:
str1: Hello, World!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:c语言中如何给字符串赋值