scanf(..);输入字符按下回车键后,gets()函数会把回车键当做输入的字符。所以在执行gets()前要把回车过滤掉!!
改正后代码:
#include
main()
{
char a1[5] = "",a2[5] = "",a3[5] = "",a4[5] = "";
scanf("%s%s",a1,a2);
printf("a1=%s\n",a1);
printf("a2=%s\n",a2);
printf("a3=%s\n",a3);
printf("a4=%s\n",a4);
printf("请输入a3:");
getchar(); //过滤回车
gets(a3);printf("a1=%s\n",a1);
printf("a2=%s\n",a2);
printf("a3=%s\n",a3);
printf("a4=%s\n",a4);
printf("请输入a4:");
gets(a4);
printf("a1=%s\n",a1);
printf("a2=%s\n",a2);
printf("a3=%s\n",a3);
printf("a4=%s\n",a4);
}