c语言字符串赋值给数组的有哪些方法
在C语言中,将一个字符串赋值给字符数组的方法有两种:
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Hello, World!";
char str2[20];
strcpy(str2, str1);
printf("str2: %s
", str2);
return 0;
}
#include <stdio.h>
int main() {
char str1[] = "Hello, World!";
char str2[20];
for (int i = 0; str1[i] != '