当你输入超过密码长度hehe1234,你的input里面的数据就是{h,e,h,e,1,2,3,4...}这时候你再输入正确密码hehe123,前面的都被覆盖,但是4还保留在数组里面,你的input其实还是hehe1234,所以你不可能再得到正确密码。
c语言输入六位数密码,七位也能输入打印,这是因为第七位是没有办法显示的。这里使用一个简单的账号密码输入并打印的程序来分析。输入 #include<stdio.h>intmain(){ char account[20] = {0 }int password[20] = {0 }printf("请输入账号:")
#includevoid
main()
{
int
n,password=123456,i=1
while(1)
{
printf("输入密码:")
scanf("%d",&n)
if(n==password)
printf("welcome
to
use
the
software\n")
else
{
if(i<3)
printf("剩余的可输入密码的次数为:%d\n",3-i)
else
printf("password
error
!
you
can
not
use
the
software\n")
i++
}
if(i>=4||n==password)break
}
}
这个是不需要用return的,简明一点,初学的应该会