密码程序不工作....请帮助....正确输入也说密码错误
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
void main()
{
clrscr();
int ctr=0;
int o;
char pass[5];
cout<<"enter password";
for(int i=0;i<5 && (o=getch())!=13 ;i++)
{
pass[i]=o;
putch('*');
}
ctr=strcmp(pass,"luck");
cout<<ctr;
if(ctr==0)
{
cout<<"welcome";
}
else
{
cout<<"wrong password";
}
getch();
}
我想知道为什么这个密码程序不起作用....他们还有其他方法吗
最佳答案
为了能够使用 strcmp()
,您需要以 NUL 终止 pass
。您还需要确保 pass
足够大以容纳 NUL。
关于c++ - C++密码程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14170154/