Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
不使用 strcpy 函数将所有字符从一个字符数组复制到另一个字符数组。
char s1[80],s2[80]; int i; printf("input s2"); scanf("%s",&s2); for(i=0;i<=strlen(s2);i++) s1[i]=s2[i]; printf("s1:%s",s1);
而不是scanf,使用gets函数来获取带空格的输入。
#include<stdio.h> int main() { char s1[80],s2[80]; int i; printf("input s2"); // scanf("%c",&s2); gets(s2); printf("%d",strlen(s2)); for(i=0;i<strlen(s2);i++) { s1[i]=s2[i]; } printf("s1:%s",s1); }