#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
clrscr();
char username[15], password[15], ch, usr[15], pass[15];
int choice, i=0, found=0;
printf("1.Add Admin");
printf("\n2.Log-in Admin");
printf("\n3.Exit");
printf("\nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: FILE *acc;
if((acc = fopen("c:\\account.txt","a+")) == NULL)
printf("FILE NOT FOUND!");
else
{
do
{
fscanf(acc,"%s %s%",username, password);
}while(!feof(acc));
}
printf("\nEnter desired username: ");
scanf("%s",username);
printf("Enter desired password: ");
while(ch != 13)
{
ch = getch();
password[i] = ch;
i++;
printf("*");
}
password[i]='\0';
fprintf(acc,"%s %s\n",username,password);
fclose(acc);break;
case 2: FILE *log;
log = fopen("c:\\account.txt","r");
printf("Username: "); //user input username and password//
scanf("%s",usr);
printf("Password: ");
while(ch != 13)
{
ch = getch();
pass[i] = ch;
i++;
printf("*");
}
pass[i]='\0';
while(!feof(log)&& found == 0)
{
fscanf(log,"%s %s",username,password); //this is where i am having some problem//
if(strcmp(usr,username) == 0 && strcmp(pass,password));
found = 1;
if(found == 1)
printf("\nWelcome!");
else
printf("\nInvalid username or password");
}
fclose(log);
}
getch();
return(0);
}
我无法验证工作,它总是说欢迎,即使它有错误的用户名和密码。 如何将用户输入字符串与文件中的数据进行比较? 不幸的是turbo c是必需的。用户名和密码验证turbo c
你为什么成炭阅读密码字符? – Haris 2014-10-09 09:11:43
尝试将您的代码缩减为显示问题 – thumbmunkeys 2014-10-09 09:11:48
以将字符替换为“*”的代码片段。 – Dme12 2014-10-09 09:19:06