当我尝试从if条件的Login方法中调用ShowMeMine(struct user_node userob)时,即使密码正确,也是说我的密码错误。如果我从if condition.enter行中删除该行,则表示登录成功
我将此文件另存为.h扩展名。

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

struct user_node{
    char username[20];
    char password[100];
    char address[200];
    int age;
    int unique_id;    //It will help in connecting user_node and his bill
};
struct bill{
    long user_bill_no;
    int show_this_bill;
    long meter_no;
    double total_amount;
    int unique_id;

};

//viewing specific person
void ShowMeMine(struct user_node userob){
    printf("");
}
//Login authentication check
void Login(struct user_node userob){
    FILE *fpread;
    fpread=fopen("userdata.DAT","rb+");
    char key[100];
    char user_name[40],password[100];
    char choice,ch;
    int x;
    int pass_count=0;
    printf("Enter your name");
    gets(user_name);
    while((ch=getch())!='.'){
        password[pass_count++]=ch;
        printf("*");
    }
    while(fread(&userob,sizeof(userob),1,fpread)==1){
        if(stricmp(user_name,userob.username)==0){
            strcpy(key,userob.password);
            userob=userob;
            break;
        }
    }
    if(strcmp(key,password)==0){
        printf("Sucessfully Logged In");
        ShowMeMine(userob);
    }
    else printf("Login Unsuccessful ");
    printf("%d",x);

}

最佳答案

您的代码不起作用的原因是,您忘记了终止读取的密码:

    while((ch=getch())!='.'){
        password[pass_count++]=ch;
        printf("*");
    }
    password[pass_count]= '\0';


附言:我不明白为什么给函数一个不使用的结构(按值),也不返回一个值。任务userob=userob;也很有趣。最后,您必须先关闭文件,然后再返回。

08-17 04:49