3. 编写一个程序,将字符数组s2中的全部字符复制到字符数组s1中。不用strcpy函数。复制时’\0’也要复制过去,’\0’后面的字符不复制。
程序代码:
#include <stdio.h>
void copyString(char s1[], char s2[]) {
int i = 0;
while(s2[i] != '\0') {
s1[i] = s2[i];
i++;
}
s1[i] = '\0';
}
int main() {
char s1[100], s2[100];
printf("输入字符串s2: ");
scanf("%s", s2);
copyString(s1, s2);
printf("s1 = %s\n", s1);
return 0;
}
标签:字符,int,s2,11.14,char,s1 From: https://www.cnblogs.com/lml66/p/17909387.html