史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   如何使用程式來確認密碼 (http://forum.slime.com.tw/thread254996.html)

zse5500 2009-11-30 07:43 PM

如何使用程式來確認密碼
 
下面的程式碼是我打的...(不是最後的完成圖的程式碼)

語法:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
main()
{
      char pass[100]="OPEN THE DOOR !",g[100];
start:
      printf("輸入密碼 :");
      fflush(stdin);
      g[0]=getch();g[1]=getch();g[2]=getch();g[3]=getch();
      g[4]=getch();g[5]=getch();g[6]=getch();g[7]=getch();
      g[8]=getch();g[9]=getch();g[10]=getch();g[11]=getch();
      g[12]=getch();g[13]=getch();g[14]=getch();g[15]=getch();
      g[16]=getch();g[17]=getch();g[18]=getch();g[19]=getch();
      g[20]='\0';
      printf("\n\n");
      printf("你輸入的是 : %s",g);
      printf("\n\n");     
      system("pause");
      goto start;
}

請問喔...

第6行的框中數字怎麼改?功能是?char pass[100]="happy new year !",g[100];

g[]=getch(); 怎麼用迴圈化簡?

要如何改成輸入的字變成"*"號?(我的程式碼不會顯示任何東西)

輸入後,可以直接按enter,不用打完(20個字)讓程式自動跳?

要如何檢查輸入的字是否為"happy new year !" ?

http://img163.imageshack.us/img163/3118/168589680.png
http://img163.imageshack.us/img163/3118/168589680.th.png

pedrowong 2009-11-30 10:02 PM

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

main()
{
char pass[100]="happy new year !",g[100];
int i;
start:
printf("輸入密碼 :");
fflush(stdin);
for (i=0;i<19;i++) {
g[i]=getch();
if (i==0 && g[i]==13) exit(0);
if (g[i]==13) {
g[i] = 0;
break;
}
putchar('*');
}
g[i+1] = 0;
printf("\n\n");
printf("你輸入的是 : %s\n",g);
if (strcmp(g,pass)==0) printf("密碼輸入正確!!!\n");
else printf("密碼輸入錯誤!!!\n");
printf("\n\n");
system("pause");
goto start;
}

zse5500 2009-12-01 09:39 PM

引用:

作者: pedrowong (文章 2206357)
#include <stdio.h>
#include <stdlib.h>
......


感謝回答喔..

我還是有些問題

請問這段是什麼意思?

if (i==0 && g[i]==13) exit(0);
if (g[i]==13)
{
g[i] = 0;
break;
}
....

pedrowong 2009-12-03 10:06 PM

感謝回答喔..

我還是有些問題

請問這段是什麼意思?

if (i==0 && g[i]==13) exit(0);
1:如果輸入是直接按換行,則結束執行。

if (g[i]==13)
{
2:將換行字改為'0'。(字串最後一字必需為'0')
g[i] = 0;
break;
}

zse5500 2009-12-05 01:30 PM

那...

g[i]==13


"13"是ENTER的意思?

如果是其他數字呢??


所有時間均為台北時間。現在的時間是 09:54 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1