标题:运行错误,请指出
只看楼主
告白
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2016-12-24
结帖率:60%
 问题点数:0 回复次数:0 
运行错误,请指出
#include<stdio.h>
#include<string.h>           //字符//
#include<malloc.h>
#include<stdlib.h>           //标准库//
#include<conio.h>            //控制输入输出//
#define NULL 0

struct student  //结构体//
{
    long num;                 //学号//
    char name[20];
    int  c;                   //C代表班级//
    char phone[11];
    char email[20];
    int dorm;                //家庭住址//
    struct student *next;    //链表,下一个节点的地址
};

struct student *stu;
int n;

void menu(void)               //主菜单函数//
{
system("cls");
puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
puts("$$$$$                    学生管理系统                         $$$$$");
puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
puts("$$$$$                    1=录入学生通讯录信息                 $$$$$");
puts("$$$$$                    2=列出所有学生通讯录                 $$$$$");
puts("$$$$$                    3=按姓名查询信息                     $$$$$");
puts("$$$$$                    4=按姓名查询信息                     $$$$$");
puts("$$$$$                    5=删除学生信息                       $$$$$");
puts("$$$$$                    6=按学号将学生通讯录信息排序         $$$$$");
puts("$$$$$                    0=保存信息,退出                     $$$$$");
puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
}

struct student *shuru(void)    //输入函数//
{
    system("cls");
struct student *s1,*s2;
n=1;
int num;
puts("请输入学生个数:");
scanf("%d",&num);
s1=s2=(struct student *)malloc(sizeof(struct student));
puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
puts("请输入学号:");
scanf("%ld",&s1->num);
puts("请输入学生姓名:");
scanf("%s",s1->name);//&//
puts("请输入班级:");
scanf("%d",&s1->c);
puts("请输入电话号码:");
scanf("%s",&s1->phone);
puts("请输入电子邮件:");
scanf("%s",&s1->email);
puts("请输入学生宿舍:");
scanf("%d",&s1->dorm);
stu=s1;
while(n<num)
{
    s2->next=s1;
    s2=s1;
    s1=(struct student *)malloc(sizeof(struct student));
    puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
    puts("请输入学号:");
    scanf("%ld",&s1->num);
    puts("请输入学生姓名:");
    scanf("%s",s1->name);
    puts("请输入班级:");
    scanf("%d",&s1->c);
    puts("请输入电话号码:");
    scanf("%s",s1->phone);
    puts("请输入电子邮件:");
    scanf("%s",s1->email);
    puts("请输入学生宿舍:");
    scanf("%d",&s1->dorm);
    n=n+1;
}
puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
s2->next=s1;
s2=s1;
s2->next=NULL;
return stu;
//system("cls");
}

void shuchu(struct student *s)
   //输出单个学生信息//
{
printf("*  %-8ld",s->num);
printf("%-15s",s->name);
printf("%-8d",s->c);
printf("%-15s",s->phone);
printf("%-15s",s->email);
printf("%-5d  *\n",s->dorm);
}

void findall()  //输出所有学生信息//
{
     system("cls");
     struct student s;////////////////*
     //if(n=2)
     //printf("\n现在有%d个学生,分别是:\n",n);
     //else;
     printf("\n现在有%d个学生信息,分别是: \n",n);
     puts("___________________________________________________________");
     puts("*  学号    姓名       班级     电话     电子邮件    宿舍  *");
     s=stu;
     while(s!=NULL)
     {
         shuchu(s);
         s=s->next;
     }
     puts("___________________________________________________________");
     puts("返回主菜单请按【9】");
     if(getche()=='9') menu();
}

void findname()//按姓名查询
{
    system("cls");
    struct stduent *s;
    char name[20];
    printf("\n请输入你要查询的学生姓名:\n");
    scanf("%s",name);
    s=stu;
    while(strcmp(s->name,name)!=0)
    {
        s=s->next;
    }
    if(s==NULL)
    {
        puts("无该学生姓名!");
        goto end;
    }
    else
    {
        puts("*  学号    姓名       班级     电话     电子邮件    宿舍  *");
        shuchu(s);
    }
end:;
    puts("返回主菜单请按【9】");
    if(getche()=='9') menu();
}

void findnum()    //按学号查找函数//
{
    system("cle");
    struct stduent *s;
    puts("请输入需要查找的学号:");
    long i;
    scanf("%ld",&i);
    s=stu;

    while (s->num!=i)
    {
        s=s->next;
    }
    if(s==NULL)
    {
         puts("对不起,无该学生学号"); goto end;
    }
    else
    {
        puts("该学生的信息为:");
        puts("*  学号    姓名       班级     电话     电子邮件    宿舍  *");
        shuchu(s);
    }
end:;
    puts("返回主菜单请按【9】");
    if(getche()=='9') menu();
}

struct student *shanchu(stuct student*stu)  //删除函数//
{
    system("cls");
    long num;
    char s;
    struct student *s1,*s2;
    if(stu==NULL)
    {
        puts("没有任何学生学信息。");
        goto end;
    }
    puts("请输入需要删除的学生学号");
    scanf("%ld",&num);
    s1=stu;
    puts("警告:是否删除此学生信息(Y/N)?");
    scanf("%s",&s);
    if((s=='Y')||(s=='y'))
    {
        while((num!=s1->num)&&(s1->next!=NULL))
        {
            s2=s1;s1=s1->next;
        }

        if(num==s1->num)
        {
            puts("该学生的信息为:");
            puts("*  学号    姓名       班级     电话     电子邮件    宿舍  *");
            shuchu(s1);
            if(s1==stu)
                stu=s1->next;
            else
                s2->next=s1->next;
            puts("该学生的信息已删除!剩下的学生信息如下:");
            n=n-1;
        }
    }
    findall();
    return(stu);
    end:;
    puts("返回主菜单请按【9】");
    if(getche()=='9') menu();
}

void paixu()
{
    struct student *p,*p1,*p2;
    int i,j;
    int temp;
    char b[20];
    if(stu==NULL)
    {
        printf("\n学生信息部存在\n");
        goto end;
    }
    for(i=0;i<n-1;i++)
    {
        p1=stu;
        for(j=0;j<n-1;j++)
        {
            p2=p1->next;
            if(p1->num>p2->num)
            {
                temp=p1->num;
                p1->num=p2->num;
                p2->num=temp;
                strcpy(b,p1->name);
                strcpy(p1->name,p2->name);
                strcpy(p2->name,b);
                temp=p1->C;
                p1->C=p2->C;
                p2->C=temp;
                strcpy(b,p1->phone);
                strcpy(p1->phone,p2->phone);
                strcpy(p2->phone,b);
                strcpy(b,p1->email);
                strcpy(p1->email,p2->email);
                strcpy(p2->email,b);
                temp=p1->dorm;
                p1->dorm=p2->dorm;
                p2->dorm=temp;
            }
            p1=p1->next;
        }
    }
    p=stu;
    puts("按学号顺序重排完毕!");


    puts("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
    puts("*  学号    姓名       班级     电话     电子邮件    宿舍  *");
    while(p!=NULL)
    {
        printf("*  %-8ld",p->num);
        printf("%-15s",p->name);
        printf("%-8d",p->C);
        printf("%-15s",p->phone);
        printf("%-15s",p->email);
        printf("%-5d  *\n",p->dorm);
        p=p->next;
    }
    end:;
    puts("返回主菜单请按【9】");
    if(getche()=='9')
        menu();
}




void main()     //主函数//
{
    char a;
    menu();
    puts("\n欢迎使用本通讯录系统");
    a=getche();
    while(a)
    {
        puts("");
        switch(a)
        {
        case'0':goto end ; break;
        case'1':
            puts("\n请您录入学生通讯录信息:");
            stu=shuru();
            system("cls");
            menu();
            puts("\n学生信息录入成功,请输入您的选择(0~6)\n");
            
            break;
        case'2':findall();
            puts("\n请输入你的选择(0~6):"); break;
        case'3':findname();
            puts("\n请输入你的选择(0~6):"); break;
        case'4':findnum();
            puts("\n请输入你的选择(0~6):"); break;
        case'5':stu=shanchu(stu);
            puts("\n请输入你的选择(0~6):"); break;
        case'6':paixu();
            puts("\n请输入你的选择(0~6):"); break;

        default:puts("输入有误!!按数字1键重新录入学生信息。"); break;
        }
        a=getche();
    }
end:;
    puts("欢迎再次使用!");
}
搜索更多相关主题的帖子: email 结构体 include 
2017-04-27 15:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-476486-1-1.html




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

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