为什么总是显示无效密码?它在我的另一个程序中有效,但在这个程序中却不行!我真的不知道为什么。
#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!");
}