【发布时间】:2012-07-17 17:30:12
【问题描述】:
为什么总是显示无效密码?它在我的另一个程序中有效,但在这个程序中却不行!我真的不知道为什么。
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#define MAXLTR 15
int login(void);
void welcome(void);
void gotoxy(int x,int y);
int main(void)
{
char password[MAXLTR];
printf("\nEnter password: ");
//scanf("\n%s",&password);
ltrcntr = 0;
while(buffer != 13)
{
buffer = getch();
if(buffer == 13)
break;
printf("\b**");
password[ltrcntr] = buffer;
ltrcntr++;
}
if(strcmp(password,"dlsu") == 0)
{
system("cls");
welcome();
}
else
printf("\nInvalid Password, please rerun the program.\n");
}
void gotoxy(int x, int y)
{
HANDLE eric;
COORD pogi;
pogi.X = x;
pogi.Y =y;
eric = GetStdHandle
(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition
(eric, pogi);
}
int login(void)
{
char password[MAXLTR],buffer;
int ltrcntr = 0;
printf("Enter password: ");
while(buffer != 13)
{
buffer = getch();
if(buffer == 13)
break;
printf("\b**");
password[ltrcntr] = buffer;
ltrcntr++;
}
if(strcmp(password,"dlsu")==0)
return 1;
}
void welcome(void)
{
system("Color 4F");
gotoxy(35,56);
printf("\nWelcome to SPACE INVADERS!");
}
【问题讨论】:
-
看起来你不是在终止
password。 -
另外,密码最多 14 个字母?
-
调试器创造奇迹... :)
-
@Mysticial,你刚刚失去了 90 个声望!
-
@Shahbaz:非常真实!大家都知道you need 25 letters for a good password。