| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 626 人关注过本帖
标题:c语言问题自动退出?
只看楼主 加入收藏
ppvae
Rank: 1
等 级:新手上路
帖 子:25
专家分:2
注 册:2014-1-18
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:3 
c语言问题自动退出?
可以现在c盘中存入名为password.txt的文件文件账号和密码可以设为1 2,和information.txt的文件可以存一个行数据
13207215 cheng male jiangxu 496533 1994 8 29 2017
代码没写完,每次选择用户只能选1 和只能使用查询函数。问题是进入管理员界面四次后就自动退出了。求解答
#include<stdio.h>
#include<graphics.h>
int m=0;
struct Administrator_pass{
                           char account_number[20];
                           char password[20];
                           struct Administrator_pass *next;
                          };
struct student_pass{
                    char account_number[15];
                    char password[15];
                    struct student_pass *next;
                    };
struct student{

                long int number;
                char name[20];
                long int class_number;
                long int QQ;
                char sex[10];
                char place_of_origin[15];
                int year;
                int month;
                int day;
                int graduate_year;
                struct student *next;
                };

int main(void)
{
    void Administrator_pass(char *account_number,char *password,int n);
    void student_pass(char *account_number,char *password,int n);
    void Administrator_screen();
    void search_information();
    void Administrator_choice(int n);
    void Main_screen();
    void Select_user();
    void Choice(int n);
    struct Administrator_pass *pass();
    struct student *student_information();
    struct student_pass *pass1();
    Main_screen();


    getch();
    return 0;
}
void Main_screen()
{
    int i,graphdriver,graphmode;
    char s[100];
    char t[100];
    char y[100];
    char x[100];
    char z[100];
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    cleardevice();
    setbkcolor(BLUE);
    setviewport(40,40,600,440,1);
    setfillstyle(1,2);
    setcolor(YELLOW);
    rectangle(0,0,560,400);
    floodfill(50,50,14);
    rectangle(20,20,540,380);
    setfillstyle(1,13);
    floodfill(21,300,14);
    setcolor(BLACK);
    settextstyle(3,0,4);
    outtextxy(240,100,"Welcome You");
    outtextxy(170,140,"Press any key to continue ");
    outtextxy(190,160,"Note the following");
    setviewport(100,200,540,380,0);
    setcolor(14);
    setfillstyle(1,12);
    rectangle(20,20,420,120);
    settextstyle(3,0,4);
    floodfill(21,100,14);
    sprintf(s,"1 Please strictly control input format ");
    sprintf(t,"2 After the input, please press the return key");
    sprintf(y,"3 Please users to maintain the network security ");
    sprintf(x,"4 Hope you use the software ");
    sprintf(z,"5 Let's begin ");
    setcolor(YELLOW);
    outtextxy(30,30,s);
    outtextxy(30,50,t);
    outtextxy(30,70,y);
    outtextxy(30,90,x);
    outtextxy(30,110,z);
    getch();
    closegraph();
    Select_user();
}
void Select_user()
{
    int n,graphdriver,graphmode;
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    cleardevice();
    setbkcolor(RED);
    setviewport(40,40,600,440,1);
    setfillstyle(1,2);
    setcolor(YELLOW);
    rectangle(0,0,560,400);
    floodfill(50,50,14);
    rectangle(20,20,540,380);
    setfillstyle(1,13);
    floodfill(21,300,14);
    setcolor(BLACK);
    settextstyle(3,0,4);
    outtextxy(180,100,"Welcome You use the software ");
    outtextxy(180,180,"     1 Administrator");
    outtextxy(180,230,"     2 Student user");
    outtextxy(180,280,"     0 Quit");
    printf("\n                           In put you choice:");
    scanf("%d",&n);
    Choice(n);
}
void Choice(int n)
{
    char password[20];
    char account_number[20];
    int graphdriver,graphmode;
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
        switch(n){
            case 1:
                m++;
                cleardevice();
                setbkcolor(6);
                setviewport(40,40,100,100,1);
                setfillstyle(1,2);
                setcolor(YELLOW);
                printf("\n\n\n\n\n\n\n");
                printf("\t\t\t        ");
                printf("Welcome you!");
                printf("\n\n\n\n\n\n\n");
                printf("  ");
                printf("Input your account_number:");
                scanf("%s",account_number);
                printf("\n");
                printf("  ");
                printf("Input your password:");
                scanf("%s",password);
                Administrator_pass(account_number,password,n);
                break;
            case 2:
                cleardevice();
                setbkcolor(6);
                setviewport(40,40,100,100,1);
                setfillstyle(1,2);
                setcolor(YELLOW);
                printf("\n\n\n\n\n\n\n");
                printf("\t\t\t        ");
                printf("Welcome you!");
                printf("\n\n\n\n\n\n\n");
                printf("  ");
                printf("Input your account_number:");
                scanf("%s",account_number);
                printf("\n");
                printf("  ");
                printf("Input your password:");
                scanf("%s",password);
                student_pass(account_number,password,n);
                break;
            case 0:
                cleardevice();
                setbkcolor(6);
                setviewport(40,40,100,100,1);
                setfillstyle(1,2);
                setcolor(YELLOW);
                printf("\n\n\n\n\n\n\n\n\n\n\n");
                printf("\t\t\t     ");
                printf("Welcome to your next coming!");
                return;
            default:
                cleardevice();
                setbkcolor(6);
                setviewport(40,40,100,100,1);
                setfillstyle(1,2);
                setcolor(YELLOW);
                printf("Sorry ,please input correct choice!");
                printf("\nPress any key to continue");
                getch();
                Select_user();
                break;
    }
}
void Administrator_pass(char *account_number,char *password,int n)
{
    struct Administrator_pass *head,*p;
    int count=0;
    int graphdriver,graphmode;
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    head=pass();
    for(p=head;p!=NULL;p=p->next){
        if((strcmp(password,p->password)==0)&&(strcmp(p->account_number,account_number)==0)){
            count++;
            Administrator_screen();

        }
    }
    if(m==3){
        cleardevice();
        setbkcolor(6);
        setviewport(40,40,100,100,1);
        setfillstyle(1,2);
        setcolor(YELLOW);
        printf("Sorry! worry times is too many!\n");
        printf("Press any key to quit");
        getch();
        cleardevice();
        setbkcolor(6);
        setviewport(40,40,100,100,1);
        setfillstyle(1,2);
        setcolor(YELLOW);
        printf("\n\n\n\n\n\n\n\n\n\n\n");
        printf("\t\t\t     ");
        printf("Welcome to your next coming!");
        return;
    }
    if(count==0){

        cleardevice();
        setbkcolor(6);
        setviewport(40,40,100,100,1);
        setfillstyle(1,2);
        setcolor(YELLOW);
        printf("Sorry! your account_number or password is worry!\n");
        printf("Press any key to continue");
        getch();
        Choice(n);
    }


}
struct Administrator_pass *pass()
{
    FILE *fp;
    struct Administrator_pass *head,*p,*q;
    int size=sizeof(struct Administrator_pass);
    p=q=head=NULL;
    fp=fopen("c:\\password.txt","r");
    while(!feof(fp)){
    p=(struct Administrator_pass *)malloc(size);
    fscanf(fp,"%s%s",p->account_number,p->password);
    p->next=NULL;
    if(head==NULL)
       head=p;
    else
       q->next=p;
    q=p;
    }
    fclose(fp);
    return head;
}
void student_pass(char *account_number,char *password,int n)
{
    struct student_pass *head,*p;
    int count=0;

    int graphdriver,graphmode;
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    head=pass1();
    for(p=head;p!=NULL;p=p->next){
        if((strcmp(password,p->password)==0)&&(strcmp(p->account_number,account_number)==0)){
            count++;
        }
    }
    if(m==3){
        cleardevice();
        setbkcolor(6);
        setviewport(40,40,100,100,1);
        setfillstyle(1,2);
        setcolor(YELLOW);
        printf("Sorry! worry times is too many!\n");
        printf("Press any key to quit");
        getch();
        cleardevice();
        setbkcolor(6);
        setviewport(40,40,100,100,1);
        setfillstyle(1,2);
        setcolor(YELLOW);
        printf("\n\n\n\n\n\n\n\n\n\n\n");
        printf("\t\t\t     ");
        printf("Welcome to your next coming!");
        return;
    }
    if(count==0){

        cleardevice();
        setbkcolor(6);
        setviewport(40,40,100,100,1);
        setfillstyle(1,2);
        setcolor(YELLOW);
        printf("Sorry! your account_number or password is worry!\n");
        printf("Press any key to continue");
        Choice(n);
    }
    getchar();


}
struct student_pass *pass1()
{
    FILE *fp;
    struct student_pass *head,*p,*q;
    int size=sizeof(struct Administrator_pass);
    p=q=head=NULL;
    fp=fopen("c:\\pass.txt","r");
    while(!feof(fp)){
    p=(struct student_pass *)malloc(size);
    fscanf(fp,"%s%s",p->account_number,p->password);
    p->next=NULL;
    if(head==NULL)
       head=p;
    else
       q->next=p;
    q=p;
    }
    fclose(fp);
    return head;
}
void Administrator_screen()
{
    int n,graphdriver,graphmode;
    char s[100];
    char t[100];
    char y[100];
    char x[100];
    char z[100];
    char a[100];
    char b[100];
    char c[100];
    char d[100];
    char e[10];
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    cleardevice();
    setbkcolor(BLUE);
    setviewport(40,40,600,440,1);
    setfillstyle(1,2);
    setcolor(YELLOW);
    rectangle(0,0,560,400);
    floodfill(50,50,14);
    rectangle(20,20,540,380);
    setfillstyle(1,13);
    floodfill(21,300,14);
    setcolor(BLACK);
    settextstyle(3,0,4);
    outtextxy(240,100,"Welcome You");
    setviewport(100,200,540,380,0);
    setcolor(14);
    setfillstyle(1,12);
    rectangle(20,20,420,130);
    settextstyle(3,0,4);
    floodfill(21,100,14);
    sprintf(s,"1 search student's information ");
    sprintf(t,"2 change's student's information");
    sprintf(y,"3 delect student's information ");
    sprintf(x,"4 increase students'information");
    sprintf(z,"5 view student's information");
    sprintf(a,"6 view the public'information of student");
    sprintf(b,"7 delect the public'information of student");
    sprintf(c,"8 change student'password");
    sprintf(d,"9 change own password");
    sprintf(e,"0 Quit");
    setcolor(YELLOW);
    outtextxy(30,30,s);
    outtextxy(30,40,t);
    outtextxy(30,50,y);
    outtextxy(30,60,x);
    outtextxy(30,70,z);
    outtextxy(30,80,a);
    outtextxy(30,90,b);
    outtextxy(30,100,c);
    outtextxy(30,110,d);
    outtextxy(30,120,e);
    getchar();
    printf("\n                           In put you choice:");
    scanf("%d",&n);
    Administrator_choice(n);

}
void Administrator_choice(int n)
{
    switch(n){
        case 1:
            search_information();
            break;
    }
}
void search_information()
{

    struct student *p,*head;
    int b=1,c;
    int count=0;
    long int student_number;
    char s[100];
    char t[100];
    char y[100];
    int i,graphdriver,graphmode;
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    cleardevice();
    setbkcolor(BLUE);
    setviewport(40,40,600,440,1);
    setfillstyle(1,2);
    setcolor(YELLOW);
    rectangle(0,0,560,400);
    floodfill(50,50,14);
    rectangle(20,20,540,380);
    setfillstyle(1,13);
    floodfill(21,300,14);
    setcolor(BLACK);
    settextstyle(3,0,4);
    outtextxy(240,100,"Welcome You");
    setviewport(100,200,540,380,0);
    setcolor(14);
    setfillstyle(1,12);
    rectangle(20,20,420,120);
    settextstyle(3,0,4);
    floodfill(21,100,14);
    sprintf(s,"1 study number");
    sprintf(t,"2 student's name");
    sprintf(y,"3 class'snumber");
    outtextxy(30,30,s);
    outtextxy(30,50,t);
    outtextxy(30,70,y);
    printf("\n                           In put you choice:");
    scanf("%d",&i);
    while(b==1){
        switch(i){
            case 1:
                head=student_information();
                cleardevice();
                setbkcolor(6);
                setviewport(40,40,100,100,1);
                setfillstyle(1,2);
                setcolor(YELLOW);
                printf("please input student's number:");
                scanf("%ld",&student_number);
                for(p=head;p!=NULL;p=p->next){
                    if(p->number==student_number){
                        printf("number:%ld\n",p->number);
                        printf("name:%s\n",p->name);
                        printf("sex:%s\n",p->sex);
                        printf("place_of_origin:%s\n",p->place_of_origin);
                        printf("QQ:%ld\n",p->QQ);
                        printf("birthday:%d/%d/%d\n",p->year,p->month,p->day);
                        printf("class_number:%ld\n",p->class_number);
                        printf("graduate_time:%d\n",p->graduate_year);
                        count++;
                        getchar();
                        printf("Do your want to go on 1 Yes or 2 No:");
                        scanf("%d",&b);
                    }
                }
                if(count==0){
                    printf("sorry! It is a wrong number!\n");
                    printf("do you want to go on? 1 Yes or 2 No:");
                    scanf("%d",&b);
                }
                if(b==2){
                    printf("\nDo you want to coninue? 1 Yes or 2 No:");
                    scanf("%d",&c);
                    if(c==1){
                        Administrator_screen();
                    }
                    else{
                        cleardevice();
                        setbkcolor(6);
                        setviewport(40,40,100,100,1);
                        setfillstyle(1,2);
                        setcolor(YELLOW);
                        printf("\n\n\n\n\n");
                        printf("\t\t\t     ");
                        printf("Welcome to your next coming!");
                        return ;
                    }
                }
                count=0;
                break;
        }
    }
}
struct student *student_information()
{
    int size1=sizeof(struct student);
    FILE *fp1;
    struct student *p,*head,*q;
    q=head=p=NULL;
    if((fp1=fopen("c:\\student.txt","r"))==NULL)
       return NULL;
    else{
       while(!feof(fp1)){
        p=(struct student *)malloc(size1);
        fscanf(fp1,"%ld%s%s%s%ld%d%d%d%ld%d ",&p->number,p->name,p->sex,p->place_of_origin,&p->QQ,&p->year,&p->month,&p->day,&p->class_number,&p->graduate_year);
        p->next=NULL;
        if(head==NULL)
           head=p;
        else
           q->next=p;
        q=p;
       }
     }
    fclose(fp1);
    return head;
}

搜索更多相关主题的帖子: password include 管理员 c语言 cheng 
2014-06-09 08:43
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:14 
太长了

总有那身价贱的人给作业贴回复完整的代码
2014-06-09 08:55
ppvae
Rank: 1
等 级:新手上路
帖 子:25
专家分:2
注 册:2014-1-18
收藏
得分:0 
回复 2 楼 embed_xuel
其实只要是后面那个
void Administrator_screen()
{
    int n,graphdriver,graphmode;
    char s[100];
    char t[100];
    char y[100];
    char x[100];
    char z[100];
    char a[100];
    char b[100];
    char c[100];
    char d[100];
    char e[10];
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    cleardevice();
    setbkcolor(BLUE);
    setviewport(40,40,600,440,1);
    setfillstyle(1,2);
    setcolor(YELLOW);
    rectangle(0,0,560,400);
    floodfill(50,50,14);
    rectangle(20,20,540,380);
    setfillstyle(1,13);
    floodfill(21,300,14);
    setcolor(BLACK);
    settextstyle(3,0,4);
    outtextxy(240,100,"Welcome You");
    setviewport(100,200,540,380,0);
    setcolor(14);
    setfillstyle(1,12);
    rectangle(20,20,420,130);
    settextstyle(3,0,4);
    floodfill(21,100,14);
    sprintf(s,"1 search student's information ");
    sprintf(t,"2 change's student's information");
    sprintf(y,"3 delect student's information ");
    sprintf(x,"4 increase students'information");
    sprintf(z,"5 view student's information");
    sprintf(a,"6 view the public'information of student");
    sprintf(b,"7 delect the public'information of student");
    sprintf(c,"8 change student'password");
    sprintf(d,"9 change own password");
    sprintf(e,"0 Quit");
    setcolor(YELLOW);
    outtextxy(30,30,s);
    outtextxy(30,40,t);
    outtextxy(30,50,y);
    outtextxy(30,60,x);
    outtextxy(30,70,z);
    outtextxy(30,80,a);
    outtextxy(30,90,b);
    outtextxy(30,100,c);
    outtextxy(30,110,d);
    outtextxy(30,120,e);
    getchar();
    printf("\n                           In put you choice:");
    scanf("%d",&n);
    Administrator_choice(n);

}
void Administrator_choice(int n)
{
    switch(n){
        case 1:
            search_information();
            break;
    }
}
void search_information()
{

    struct student *p,*head;
    int b=1,c;
    int count=0;
    long int student_number;
    char s[100];
    char t[100];
    char y[100];
    int i,graphdriver,graphmode;
    graphdriver=DETECT;
    initgraph(&graphdriver,&graphmode,"");
    cleardevice();
    setbkcolor(BLUE);
    setviewport(40,40,600,440,1);
    setfillstyle(1,2);
    setcolor(YELLOW);
    rectangle(0,0,560,400);
    floodfill(50,50,14);
    rectangle(20,20,540,380);
    setfillstyle(1,13);
    floodfill(21,300,14);
    setcolor(BLACK);
    settextstyle(3,0,4);
    outtextxy(240,100,"Welcome You");
    setviewport(100,200,540,380,0);
    setcolor(14);
    setfillstyle(1,12);
    rectangle(20,20,420,120);
    settextstyle(3,0,4);
    floodfill(21,100,14);
    sprintf(s,"1 study number");
    sprintf(t,"2 student's name");
    sprintf(y,"3 class'snumber");
    outtextxy(30,30,s);
    outtextxy(30,50,t);
    outtextxy(30,70,y);
    printf("\n                           In put you choice:");
    scanf("%d",&i);
    while(b==1){
        switch(i){
            case 1:
                head=student_information();
                cleardevice();
                setbkcolor(6);
                setviewport(40,40,100,100,1);
                setfillstyle(1,2);
                setcolor(YELLOW);
                printf("please input student's number:");
                scanf("%ld",&student_number);
                for(p=head;p!=NULL;p=p->next){
                    if(p->number==student_number){
                        printf("number:%ld\n",p->number);
                        printf("name:%s\n",p->name);
                        printf("sex:%s\n",p->sex);
                        printf("place_of_origin:%s\n",p->place_of_origin);
                        printf("QQ:%ld\n",p->QQ);
                        printf("birthday:%d/%d/%d\n",p->year,p->month,p->day);
                        printf("class_number:%ld\n",p->class_number);
                        printf("graduate_time:%d\n",p->graduate_year);
                        count++;
                        getchar();
                        printf("Do your want to go on 1 Yes or 2 No:");
                        scanf("%d",&b);
                    }
                }
                if(count==0){
                    printf("sorry! It is a wrong number!\n");
                    printf("do you want to go on? 1 Yes or 2 No:");
                    scanf("%d",&b);
                }
                if(b==2){
                    printf("\nDo you want to coninue? 1 Yes or 2 No:");
                    scanf("%d",&c);
                    if(c==1){
                        Administrator_screen();
                    }
                    else{
                        cleardevice();
                        setbkcolor(6);
                        setviewport(40,40,100,100,1);
                        setfillstyle(1,2);
                        setcolor(YELLOW);
                        printf("\n\n\n\n\n");
                        printf("\t\t\t     ");
                        printf("Welcome to your next coming!");
                        return ;
                    }
                }
                count=0;
                break;
        }
    }
}
这些函数的问题。
2014-06-09 09:04
ppvae
Rank: 1
等 级:新手上路
帖 子:25
专家分:2
注 册:2014-1-18
收藏
得分:0 
回复 2 楼 embed_xuel
我发现我把图形界面的代码全删了,它运行一点错误都没有额。求大神解答
2014-06-09 16:13
快速回复:c语言问题自动退出?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017510 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved