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("請輸入a4:");
gets(a4);
/*puts(a1);
puts(a2);
puts(a3);
puts(a4);*/
}
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);
/*puts(a1);
puts(a2);
puts(a3);
puts(a4);*/
printf("a1=%s\n",a1);
printf("a2=%s\n",a2);
printf("a3=%s\n",a3);
printf("a4=%s\n",a4);
}