這是我的項目代碼。它還沒有完成,因爲我堅持最後的scanf
(在printf("Enter option:")
之後)。按下兩個鍵後,我的程序終止。我也嘗試過char和%c,但它不起作用。希望您能夠幫助我。我無法輸入一個字符。我的程序終止
void main()
{
char user[20], pass[500];
int i, a;
clrscr();
gotoxy(30,7); printf("ACCESS THE SYSTEM");
gotoxy(28,9); printf("Username: ");
gets(user);
gotoxy(28,11); printf("Password: ");
for(i = 0; i< 500; i++)
{
pass[i] = getch();
if(pass[i] == 13)
{
pass[i] = 0;
break;
}
printf("*");
}
gotoxy(30,15);printf("ACCESS GRANTED!");
gotoxy(24,20);printf("Please press any key to proceed: ");
scanf("%d", &a);
topics();
getch();
}
int topics(){
int opt;
clrscr();
gotoxy(25,5);printf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»");
gotoxy(25,6);printf("º Computer Programming Topics: º");
gotoxy(25,7);printf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ\n");
gotoxy(13,9);printf("Choose one:");
gotoxy(13,11);printf("[A] Conditional Statements");
gotoxy(13,13);printf("[B] Looping Statements");
gotoxy(13,15);printf("[C] Functions");
gotoxy(13,17);printf("[D] Arrays");
gotoxy(13,19);printf("[E] Strings");
gotoxy(13,22);printf("Enter option:");
gotoxy(13,23);scanf("%d", &opt);
getch();
}
*從不*使用獲取。改用fgets。只是爲了向後兼容纔得到語言保留,並且自第一次實施前約20分鐘就已棄用。不要使用它。 –
其實''gets'已經從C標準中移除了*。 –
發佈的代碼似乎是一個'ncurses'程序。發佈的代碼中缺少一個重要的細節。具體來說,哪些頭文件正在#included中? – user3629249