鱼C论坛

 找回密码
 立即注册
查看: 2512|回复: 3

求助!为什么会返回-1呢,急急!

[复制链接]
发表于 2018-12-22 16:12:39 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<stdlib.h>

struct USER
{
        long long id;
        long long password;
        struct USER *pnext;
};
void AddUser(struct USER**pphead)
{
        struct USER*newuser=(struct USER*)malloc(sizeof(struct USER));
        printf("--注册新账户--\n");
        printf("账户:");
        scanf("%lld",&newuser->id);
        printf("密码:");
        scanf("%lld",&newuser->password);
        newuser->pnext=*pphead;
        *pphead=newuser;       
}
void log_on(long*id,long*password)
{
        printf("——请输入账号和密码(未注册请先注册账户)——\n");
        printf("账号:");
        scanf("%lld",id);
        printf("密码:");
        scanf("%lld",password);
}
int confirm_user(struct USER*user,long long id,long long password)
{
       
        while(1)
        {
                if(user==NULL) //要放前面
                {
                        return -1;
                }
                if(id==user->id&&password==user->password)
                {
                        return 1;
                }
                user=user->pnext;
        }
}
int main()
{
                struct USER *phead=NULL;
                int kiss;
                long id,password;
                printf("1 登录\n");
                printf("2 注册\n");
                printf("3 退出\n");
                while(1)
                {
                        printf("请输入操作前的序号进行相应操作:");
                        scanf("%d",&kiss);
                        switch(kiss)
                        {
                                case 1:log_on(&id,&password);printf("%d\n",confirm_user(phead,id,password));break; //+break
                                case 2:AddUser(&phead);break;
                                case 3:exit(1);break;
                        }
                }
        }
QQ截图20181222161150.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-12-22 16:24:36 | 显示全部楼层
  {
                if(user==NULL) //要放前面
                {
                        return -1;
                }
你这有个  -1  ?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-22 16:57:16 | 显示全部楼层
按你的流程跑了一下,返回的是1.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-12-23 10:09:33 | 显示全部楼层
风扫地 发表于 2018-12-22 16:57
按你的流程跑了一下,返回的是1.

为什么我是-1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-3 02:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表