C语言写个程序,已知密码password=123 要求用户输入密码passWord,判断是否正确,输入错误超过3次则退出

C语言写个程序,已知密码password=123 要求用户输入密码passWord,判断是否正确,输入错误超过3次则退出。 写在主函数里。 谢谢了。分不多,只有10分了。
#include "stdio.h"
#include "string.h"
main()
{
char password[]="123",passWord[10];
int a=3,ch;
if(ch==1)
printf("输入正确");
if(ch==0)
{
a--;if(a==0)
exit(0);
else
printf("1错误,还有%d次机会",a);

}

while(a>0)
{
printf("输入密码");
scanf("%s",&passWord);

if(strcmp(password,passWord)==0)
return 1;
else return 0;

}

怎么修改啊?

#include <stdio.h>

#include <conio.h>

#include <string.h>


int main(void)

char password[32];

int i=3;

do{

printf("请输入密码:(还有%d次机会)",i);

scanf("%s",&password);

if(0==strcmp(password,"123"))

{

printf("密码输入正确!\n");

break;

}

else

{

printf("密码输入错误,请重新输入!\n");

i--;

}

}while(i>0);

getch();

return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-11
#include "stdio.h"

#include "string.h"
#include<stdlib.h>
void main()
{
int fun(int a,char password[],char passWord[]);
char password[]="123",passWord[10];
int a=3,ch;
loop1:
ch=fun(a,password,passWord);
if(ch==1)
printf("输入正确");
if(ch==0)
{
a--;
if(a==0)
exit(0);
else
{
printf("1错误,还有%d次机会",a);
goto loop1;
}

}
}
int fun(int a,char password[],char passWord[])
{
while(a>0)
{
printf("输入密码");
scanf("%s",passWord);

if(strcmp(password,passWord)==0)
return 1;
else
return 0;

}
}
相似回答