新的文职人员条例:我该解决空格为结束的标志?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 01:40:39
/*字符串连接*/
#include <stdio.h>
void main()
{
char t[20]="I do love china!",s[80];
char *p1=t,*p2=s;
printf("请输入s[]:\n");
scanf("%s",s);
printf("你刚才输入的字符是:%s\n",s);
while (*p2 != NULL)
p2++;
while(*p1 != NULL)
*p2++=*p1++;
*p2++='\0';
printf("s[] 是:\n");
for(p2=s;*p2!='\0';p2++)
printf("%c",*p2);
printf("\n");
}

当我输入hello c(注意有空格,c就不能输出) 这如何是好?

用gets() 只能以回车结束

或用getch()

字符串输入不一定用SCANF();
常用gets();
用法如:gets(s);

gets

将"scanf("%s",s); "改为"gets(p2);"即可.