标题:请问一下,如何加截止编译???
只看楼主
漠漠清幽
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-12-29
结帖率:0
已结贴  问题点数:10 回复次数:5 
请问一下,如何加截止编译???
比如就这道题,如何加截止编译

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 3
typedef struct z1
{
    char no[11];
    char name[15];
    int score[N];
    float sum;
    float average;
    int order;
    struct z1 *next;
}STUDENT;
STUDENT *init();
STUDENT *create();
STUDENT *del(STUDENT *h);
void print(STUDENT *h);
void search1(STUDENT *h);
void search2(STUDENT *h);
STUDENT *insert(STUDENT *h);
void sort(STUDENT *h);
void save(STUDENT *h);
void tongji(STUDENT *h);
int menu_select();
STUDENT *load();
void inputs(char *prompt,char *s,int count);
STUDENT *load();
main()
{
    int i;
    STUDENT *head;
    head=init();
    for(;;)
    {
        switch(menu_select())
        {
            case 0:head=init();break;
            case 1:head=create();break;
            case 2:head=insert(head);break;
            case 3:save(head);break;
            case 4:print(head);break;
            case 5:search1(head);break;
            case 6:head=del(head);break;
            case 7:sort(head);break;
            case 8:tongji(head);break;
            case 9:search2(head);break;
            case 10:exit(0);
        }
    }
}
int menu_select()
{
    char *menu[]={"************菜单************",
    "1. 输入学生成绩",
    "2. 插入学生成绩",
    "3. 保存学生记录",
    "4. 显示学生记录",
    "5. 按学号查找学生信息",
    "6. 删除指定学号的学生信息",
    "7. 按某一门课对学生成绩排序",
    "8. 统计某门课程的学生成绩",
    "9. 按姓名查找学生信息",
    "10. 退出系统"};
    char s[3];
    int c,i;
    for(i=0;i<=11;i++)
    printf("        %s\n",menu[i]);
    do
    {
        printf("\n请选择1~10中的某一个选项\n");
        scanf("%s",s);
        c=atoi(s);
    }while(c<0||c>10);
    return c;
}
STUDENT *init()
{
    return NULL;
}
STUDENT *create()
{
    int i;int s;
    STUDENT *h=NULL,*info;
    for(;;)
    {
        info=(STUDENT *)malloc(sizeof(STUDENT));
        if(!info)
        {
            printf("\n内存不足");
            return NULL;
        }
        inputs("输入学号:",info->no,11);
        if(info->no[0]=='@')break;
        inputs("输入姓名:",info->name,15);
        printf("开始输入%d门课的成绩\n",N);
        s=0;
        for(i=0;i<N;i++)
        {
            do{
                printf("第%d门分数:",i+1);
                scanf("%d",&info->score[i]);
                if(info->score[i]>100||info->score[i]<0)
                printf("输入成绩错误,请重新输入:\n");
            }while(info->score[i]>100||info->score[i]<0);
            s=s+info->score[i];
        }
        info->sum=s;
        info->average=(float)s/N;
        info->order=0;
        info->next=h;
        h=info;
    }
    return h;
}
void inputs(char *prompt,char *s,int count)
{
    char p[255];
    do
    {
        printf(prompt);
        scanf("%s",p);
        if(strlen(p)>count)
        printf("\n太长了!\n");
    }while(strlen(p)>count);
    strcpy(s,p);
}
void print(STUDENT *h)
{
    int i=0;
    STUDENT *p;
    p=h;
    printf("\n\n\n***********************学生***********************\n");
    printf("|序号|学号  | name   | math | English | computer | 总分 |平均分 |名次 |\n");
    printf("|---|-------|--------|----|----|----|------|------|---|\n");
    while(p!=NULL)
    {
        i++;
        printf("|%3d |%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",i,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        p=p->next;
    }
    printf("***********************end***********************\n");
}
STUDENT *del(STUDENT *h)
{
    STUDENT *p,*q;
    char s[11];
    printf("请输入要删除的学生的学号\n");
    scanf("%s",s);
    q=p=h;
    while(strcmp(p->no,s)&&p!=NULL)
    {
        q=p;
        p=p->next;
    }
    if(p==NULL)
    printf("\n链表中没有学号为%s的学生\n",s);
    else
    {
        printf("\n\n\n***********************找到了***********************\n");
    printf("|学号    |    name  | math  |  English  | computer |  总分  | 平均分 | 名次 |\n");
    printf("|----------|----------|----|----|----|------|------|---|\n");
    printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
    printf("***********************end***********************\n");
    printf("请按任意键删除\n");
    getchar();
    if(p==h)
    h=p->next;
    else q->next=p->next;
    free(p);
    printf("\n已经删除学号为%s的学生\n",s);
    printf("不要忘了保存数据\n");
    }
    return h;
}
void search1(STUDENT *h)
{
    STUDENT *p;
    char s[11];
    printf("请输入你要查找的同学的学号\n");
    scanf("%s",s);
    p=h;
    while(strcmp(p->no,s)&&p!=NULL)
    p=p->next;
    if(p==NULL)
    printf("'n没有学号为%s的学生\n",s);
    else
    {
        printf("\n\n\n***********************找到了***********************\n");
        printf("|学号      |    姓名   | 数学  |  英语  | 计算机 |  总分  | 平均分 | 名次 |\n");
        printf("|----------|-----------|----|----|----|------|------|---|\n");
        printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        printf("***********************end***********************\n");
    }
}
void search2(STUDENT *h)
{
    STUDENT *p;
    char s[11];
    printf("请输入你要查找的同学的姓名\n");
    scanf("%s",s);
    p=h;
    while(strcmp(p->name,s)&&p!=NULL)
    p=p->next;
    if(p==NULL)
    printf("\n没有姓名为%s的学生\n",s);
    else
    {
        printf("\n\n\n***********************找到了***********************\n");
        printf("|学号      |   name  | math  |  English  | computer |  总分  | 平均分 | 名次 |\n");
        printf("|----------|-----------|----|----|----|------|------|---|\n");
        printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        printf("***********************end***********************\n");
    }
}
STUDENT *insert(STUDENT *h)
{
    STUDENT *p,*q,*info;
    char s[11];
    int s1,i;
    printf("请输入插入点的学生学号\n");
    scanf("%s",s);
    printf("\n请输入新的学生信息\n");
    info=(STUDENT *)malloc(sizeof(STUDENT));
    if(!info)
    {
        printf("\n内存不足!");
        return NULL;
    }
    inputs("输入学号:",info->no,11);
    inputs("输入姓名:",info->name,15);
    printf("请输入%d门课的分数\n",N);
    s1=0;
    for(i=0;i<N;i++)
    {
        do{
            printf("分数%d",i+1);
            scanf("%d",&info->score[i]);
            if(info->score[i]>100||info->score[i]<0)
            printf("输入数据有误,请重新输入\n");
        }while(info->score[i]>100||info->score[i]<0);
        s1=s1+info->score[i];
    }
    info->sum=s1;
    info->average=(float)s1/N;
    info->order=0;
    info->next=NULL;
    p=h;
    q=h;
    while(strcmp(p->no,s)&&p!=NULL)
    {q=p;p=p->next;}
    if(p==NULL)
    if(p==h)
    h=info;
    else q->next=info;
    else
    if(p==h)
    {
        info->next=p;
        h=info;
    }
    else
    {
        info->next=p;
        q->next=info;
    }
    printf("\n已经插入了%s这个学生\n",info->name);
    printf("----不要忘了存盘啊--\n");
    return(h);
}
void save(STUDENT *h)
{
    FILE *fp;
    STUDENT *p;
    char outfile[10];
    printf("请输入保存文件的文件名,例如 c:\\f1\\te.txt:\n");
    scanf("%s",outfile);
    if((fp=fopen(outfile,"wb"))==NULL)
    {
        printf("不能打开文件\n");
        exit(1);
    }
    printf("\n正在保存......\n");
    p=h;
    while(p!=NULL)
    {
        fwrite(p,sizeof(STUDENT),1,fp);
        p=p->next;
    }
    fclose(fp);
    printf("------保存成功!!!------\n");
}
void sort(STUDENT *h)
{
    int i=0,j;
    STUDENT *p,*q,*t,*h1;
    printf("请输入要按哪门课程的编号来排序:(1.数学 2.英语 3.计算机)\n");
    scanf("%d",&j);
    h1=h->next;
    h->next=NULL;
    while(h1!=NULL)
    {
        t=h1;
        h1=h1->next;
        p=h;
        q=h;
        while(t->score[j]<p->score[j]&&p!=NULL)
        {
            q=p;
            p=p->next;
        }
        if(p==q)
        {
            t->next=p;
            h=t;
        }
        else
        {
            t->next=p;
            q->next=t;
        }
    }
    p=h;
    while(p!=NULL)
    {
        i++;
        p->order=i;
        p=p->next;
    }
    print(h);
   printf("排序成功!!!\n");
}
void tongji(STUDENT *h)
{
    STUDENT *p;
    int a,b,i;
    printf("请输入课程编号\n");
    scanf("%d",&i);
    printf("请输入分数段:\n");
    scanf("%d,%d",&a,&b);
    p=h;
    while(p!=NULL)
    {
       printf("\n\n\n***********************找到了***********************\n");
       if(p->score[i]>=a&&p->score[i]<=b)
        {
          printf("|学号    |   姓名  | 数学  |  英语  | 计算机 |  总分  | 平均分 | 名次 |\n");
          printf("|--------|---------|----|----|----|------|------|---|\n");
          printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        }
        p=p->next;
    }
    printf("***********************end***********************\n");
}
搜索更多相关主题的帖子: average include create insert 如何 
2010-12-29 10:17
漠漠清幽
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-12-29
得分:0 
这个程序没有可见性错误,就是在输入时没法返回,只能不断输入!!!帮帮忙,改一下吧!!!
2010-12-29 17:47
loveminttea
Rank: 3Rank: 3
来 自:河南科技学院
等 级:论坛游侠
帖 子:95
专家分:146
注 册:2010-10-14
得分:10 
加入if 语句实现!!
2010-12-29 17:50
漠漠清幽
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-12-29
得分:0 
具体在哪加啊?
2010-12-29 17:53
漠漠清幽
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-12-29
得分:0 
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define N 3
typedef struct z1
{
    char no[11];
    char name[15];
    int score[N];
    float sum;
    float average;
    int order;
    struct z1 *next;
}STUDENT;
STUDENT *init();
STUDENT *create();
STUDENT *del(STUDENT *h);
void print(STUDENT *h);
void search1(STUDENT *h);
void search2(STUDENT *h);
STUDENT *insert(STUDENT *h);
void sort(STUDENT *h);
void save(STUDENT *h);
void tongji(STUDENT *h);
int menu_select();
STUDENT *load();
void inputs(char *prompt,char *s,int count);
STUDENT *load();
main()
{
    int i;
    STUDENT *head;
    head=init();
    for(;;)
    {
        switch(menu_select())
        {
            case 0:head=init();break;
            case 1:head=create();break;
            case 2:head=insert(head);break;
            case 3:save(head);break;
            case 4:print(head);break;
            case 5:search1(head);break;
            case 6:head=del(head);break;
            case 7:sort(head);break;
            case 8:tongji(head);break;
            case 9:search2(head);break;
            case 10:exit(0);
        }
    }
}
int menu_select()
{
    char *menu[]={"************菜单************",
    "0. 初始化链表",
    "1. 输入学生成绩",
    "2. 插入学生成绩",
    "3. 保存学生记录",
    "4. 显示学生记录",
    "5. 按学号查找学生信息",
    "6. 删除指定学号的学生信息",
    "7. 按某一门课对学生成绩排序",
    "8. 统计某门课程的学生成绩",
    "9. 按姓名查找学生信息",
    "10. 退出系统" ,
    };
    char s[3];
    int c,i;
    for(i=0;i<=11;i++)
    printf("        %s\n",menu[i]);
    do
    {
        printf("\n请选择0~10中的某一个选项\n");
        scanf("%s",s);
        c=atoi(s);
    }while(c<0||c>10);
    return c;
}
STUDENT *init()
{
    return NULL;
}
STUDENT *create()
{
    int i;int s;int j;
    STUDENT *h=NULL,*info;
    for(;;)
    {
        info=(STUDENT *)malloc(sizeof(STUDENT));
        if(!info)
        {
            printf("\n内存不足");
            return NULL;
        }
        inputs("输入学号:",info->no,11);
        if(info->no[0]=='@')break;
        inputs("输入姓名:",info->name,15);
        printf("开始输入%d门课的成绩\n",N);
        s=0;
        for(i=0;i<N;i++)
        {
            do{
                printf("第%d门分数:",i+1);
                scanf("%d",&info->score[i]);
                if(info->score[i]>100||info->score[i]<0)
                printf("输入成绩错误,请重新输入:\n");
            }while(info->score[i]>100||info->score[i]<0);
            s=s+info->score[i];

        } printf("按11号键返回\n");
        scanf("%d",&j);
        if (j==11)
        return main();
        info->sum=s;
        info->average=(float)s/N;
        info->order=0;
        info->next=h;
        h=info;
    }
    return main();
}
void inputs(char *prompt,char *s,int count)
{
    char p[255];
    do
    {
        printf(prompt);
        scanf("%s",p);
        if(strlen(p)>count)
        printf("\n太长了!\n");
    }while(strlen(p)>count);
    strcpy(s,p);
}
void print(STUDENT *h)
{
    int i=0;
    STUDENT *p;
    p=h;
    printf("\n\n\n***********************学生***********************\n");
    printf("|序号|学号  | name   | math | English | computer | 总分 |平均分 |名次 |\n");
    printf("|---|-------|--------|----|----|----|------|------|---|\n");
    while(p!=NULL)
    {
        i++;
        printf("|%3d |%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",i,p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        p=p->next;
    }
    printf("***********************end***********************\n");
}
STUDENT *del(STUDENT *h)
{
    STUDENT *p,*q;
    char s[11];
    printf("请输入要删除的学生的学号\n");
    scanf("%s",s);
    q=p=h;
    while(strcmp(p->no,s)&&p!=NULL)
    {
        q=p;
        p=p->next;
    }
    if(p==NULL)
    printf("\n链表中没有学号为%s的学生\n",s);
    else
    {
        printf("\n\n\n***********************找到了***********************\n");
    printf("|学号    |    name  | math  |  English  | computer |  总分  | 平均分 | 名次 |\n");
    printf("|----------|----------|----|----|----|------|------|---|\n");
    printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
    printf("***********************end***********************\n");
    printf("请按任意键删除\n");
    getchar();
    if(p==h)
    h=p->next;
    else q->next=p->next;
    free(p);
    printf("\n已经删除学号为%s的学生\n",s);
    printf("不要忘了保存数据\n");
    }
    return h;
}
void search1(STUDENT *h)
{
    STUDENT *p;
    char s[11];
    printf("请输入你要查找的同学的学号\n");
    scanf("%s",s);
    p=h;
    while(strcmp(p->no,s)&&p!=NULL)
    p=p->next;
    if(p==NULL)
    printf("'n没有学号为%s的学生\n",s);
    else
    {
        printf("\n\n\n***********************找到了***********************\n");
        printf("|学号      |    姓名   | 数学  |  英语  | 计算机 |  总分  | 平均分 | 名次 |\n");
        printf("|----------|-----------|----|----|----|------|------|---|\n");
        printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        printf("***********************end***********************\n");
    }
}
void search2(STUDENT *h)
{
    STUDENT *p;
    char s[11];
    printf("请输入你要查找的同学的姓名\n");
    scanf("%s",s);
    p=h;
    while(strcmp(p->name,s)&&p!=NULL)
    p=p->next;
    if(p==NULL)
    printf("\n没有姓名为%s的学生\n",s);
    else
    {
        printf("\n\n\n***********************找到了***********************\n");
        printf("|学号      |   name  | math  |  English  | computer |  总分  | 平均分 | 名次 |\n");
        printf("|----------|-----------|----|----|----|------|------|---|\n");
        printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        printf("***********************end***********************\n");
    }
}
STUDENT *insert(STUDENT *h)
{
    STUDENT *p,*q,*info;
    char s[11];
    int s1,i;
    printf("请输入插入点的学生学号\n");
    scanf("%s",s);
    printf("\n请输入新的学生信息\n");
    info=(STUDENT *)malloc(sizeof(STUDENT));
    if(!info)
    {
        printf("\n内存不足!");
        return NULL;
    }
    inputs("输入学号:",info->no,11);
    inputs("输入姓名:",info->name,15);
    printf("请输入%d门课的分数\n",N);
    s1=0;
    for(i=0;i<N;i++)
    {
        do{
            printf("分数%d",i+1);
            scanf("%d",&info->score[i]);
            if(info->score[i]>100||info->score[i]<0)
            printf("输入数据有误,请重新输入\n");
        }while(info->score[i]>100||info->score[i]<0);
        s1=s1+info->score[i];
    }
    info->sum=s1;
    info->average=(float)s1/N;
    info->order=0;
    info->next=NULL;
    p=h;
    q=h;
    while(strcmp(p->no,s)&&p!=NULL)
    {q=p;p=p->next;}
    if(p==NULL)
    if(p==h)
    h=info;
    else q->next=info;
    else
    if(p==h)
    {
        info->next=p;
        h=info;
    }
    else
    {
        info->next=p;
        q->next=info;
    }
    printf("\n已经插入了%s这个学生\n",info->name);
    printf("----不要忘了存盘啊--\n");
    return(h);
}
void save(STUDENT *h)
{
    FILE *fp;
    STUDENT *p;
    char outfile[10];
    printf("请输入保存文件的文件名,例如 c:\\f1\\te.txt:\n");
    scanf("%s",outfile);
    if((fp=fopen(outfile,"wb"))==NULL)
    {
        printf("不能打开文件\n");
        exit(1);
    }
    printf("\n正在保存......\n");
    p=h;
    while(p!=NULL)
    {
        fwrite(p,sizeof(STUDENT),1,fp);
        p=p->next;
    }
    fclose(fp);
    printf("------保存成功!!!------\n");
    return main();
}
void sort(STUDENT *h)
{
    int i=0,j;
    STUDENT *p,*q,*t,*h1;
    printf("请输入要按哪门课程的编号来排序:(1.数学 2.英语 3.计算机)\n");
    scanf("%d",&j);
    h1=h->next;
    h->next=NULL;
    while(h1!=NULL)
    {
        t=h1;
        h1=h1->next;
        p=h;
        q=h;
        while(t->score[j]<p->score[j]&&p!=NULL)
        {
            q=p;
            p=p->next;
        }
        if(p==q)
        {
            t->next=p;
            h=t;
        }
        else
        {
            t->next=p;
            q->next=t;
        }
    }
    p=h;
    while(p!=NULL)
    {
        i++;
        p->order=i;
        p=p->next;
    }
    print(h);
   printf("排序成功!!!\n");
}
void tongji(STUDENT *h)
{
    STUDENT *p;
    int a,b,i;
    printf("请输入课程编号\n");
    scanf("%d",&i);
    printf("请输入分数段:\n");
    scanf("%d,%d",&a,&b);
    p=h;
    while(p!=NULL)
    {
       printf("\n\n\n***********************找到了***********************\n");
       if(p->score[i]>=a&&p->score[i]<=b)
        {
          printf("|学号    |   姓名  | 数学  |  英语  | 计算机 |  总分  | 平均分 | 名次 |\n");
          printf("|--------|---------|----|----|----|------|------|---|\n");
          printf("|%-10s|%-8s|%4d|%4d|%4d|%4.2f|%4.2f|%3d|\n",p->no,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
        }
        p=p->next;
    }
    printf("***********************end***********************\n");
}
2010-12-30 11:18
漠漠清幽
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-12-29
得分:0 
我又更改了一下,但发现又有新错误,文件没办法保存,请问如何改???
2010-12-30 11:19



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




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

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