[問題] 請問哪裡出錯了...(已解決)
下面這段程式碼
哪裡有問題阿...
我對照書打...
#include<stdio.h>
#include<stdlib.h>
int main (void)
{
char pass[4];
int i=0;
do {
printf("Input password :");
for (i=0;i<=3;i++)
{
pass[i]=getch(); <====卡在這行
printf("*");
}
if (!((pass[0]=='1') && (pass[1]=='2')
&& (pass[2]=='3') && (pass[3]=='4')))
printf(" Wrong password!");
printf("\n");
}
while (!((pass[0]=='1') && (pass[1]=='2')
&& (pass[2]=='3') && (pass[3]=='4')));
printf("You input the right password! \n");
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.160.42.223
→
08/21 08:21, , 1F
08/21 08:21, 1F
→
08/21 08:26, , 2F
08/21 08:26, 2F
可是...照書上寫的執行效果是
Input password :**** Wrong password! (輸入非1234時)
Input password :**** (輸入1234時)
You input the right password!
可是我的是
Input password :2345
**** Wrong password!
Input password :*
在第一次輸入錯誤後會變成這個樣子...
※ 編輯: Waterpig 來自: 118.160.42.223 (08/21 08:39)
推
08/21 08:56, , 3F
08/21 08:56, 3F
→
08/21 08:58, , 4F
08/21 08:58, 4F
→
08/21 08:59, , 5F
08/21 08:59, 5F
→
08/21 08:59, , 6F
08/21 08:59, 6F
→
08/21 09:07, , 7F
08/21 09:07, 7F
推
08/21 09:13, , 8F
08/21 09:13, 8F
→
08/21 09:14, , 9F
08/21 09:14, 9F
→
08/21 09:15, , 10F
08/21 09:15, 10F
→
08/21 09:57, , 11F
08/21 09:57, 11F
→
08/21 09:58, , 12F
08/21 09:58, 12F
→
08/21 09:59, , 13F
08/21 09:59, 13F
→
08/21 09:59, , 14F
08/21 09:59, 14F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章