开发者社区> 问答> 正文

这是一种什么样的错误呢,求科普

No this compiler or no test data

展开
收起
a123456678 2016-03-23 11:00:10 1969 0
1 条回答
写回答
取消 提交回答
  • 代码如下:

    #include 
    #include 
    #define SIZE 3
    
    struct Student
    {
    int num;
    char name[20];
    char sex[2];
    int score[5];
    float aver;
    struct Student *next;
    }stu[SIZE],*head,*p,*q;
    void save()
    {
    FILE *fp;
    int i,j;
    fp = fopen("stu.c","w+");
    head = p = (struct Student *)malloc(sizeof(struct Student));
    head ->next = &stu[0];
    for(i = 0;i < SIZE;i++)
    {
    
        scanf("%d ",&stu[i].num);
        fprintf(fp,"%d\n",stu[i].num);
        gets(stu[i].name);
        fprintf(fp,"%s\n",stu[i].name);
        gets(stu[i].sex);
        fprintf(fp,"%s\n",stu[i].sex);
        for(j = 0;j < 5;j++)
            scanf("%d",&stu[i].score[j]);
        fprintf(fp,"%d %d %d %d %d\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],
            stu[i].score[3],stu[i].score[4]);
        stu[i].aver = (stu[i].score[0] + stu[i].score[1] + stu[i].score[2] + stu[i].score[3]
            + stu[i].score[4])/5.0;
        fprintf(fp,"%f\n",stu[i].aver);
    }
    fclose(fp);
    }
    
    void sort()
    {
    FILE *fp_in,*fp_sort;
    int i,j;
    float stu_aver[SIZE];
    struct Student temp;
    fp_in = fopen("stu.c","r+");
    for(i = 0;i < SIZE;i++)
    {
    fscanf(fp_in,"%d%f",&stu[i].num,&stu[i].aver);
    //printf("fuck %f\n",stu[i].aver);
    //stu_aver[i] = stu[i].aver;
    }
    //for(i = 0;i < SIZE;i++)
    //printf("%f\n",stu_aver[i]);
    for(i = 0;i < SIZE - 1;i++)
    {
    for(j = 0;j < SIZE - 1 - i;j++)
    {
    if(stu[j].aver > stu[j + 1].aver)
    {
    temp = stu[j];
    stu[j] = stu[j + 1];
    stu[j + 1] = temp;
    }
    }
    }
    fp_sort = fopen("stu-sort","w+");
    for(i = 0;i < SIZE;i++)
    {
    fprintf(fp_sort,"%d\n",stu[i].num);
    fprintf(fp_sort,"%s\n",stu[i].name);
    fprintf(fp_sort,"%s\n",stu[i].sex);
    fprintf(fp_sort,"%d %d %d %d %d\n",stu[i].score[0],stu[i].score[1],stu[i].score[2],
    stu[i].score[3],stu[i].score[4]);
    fprintf(fp_sort,"%lf\n",stu[i].aver);
    }
    fclose(fp_sort);
    fclose(fp_in);
    }
    
    void add()
    {
    FILE *fp_new,*fp_in;
    int i;
    q = (struct Student *)malloc(sizeof(struct Student));
    scanf("%d ",&(q ->num));
    gets(q ->name);
    gets(q ->sex);
    for(i = 0;i < 5;i++)
    scanf("%d",&(q ->score[i]));
    q ->aver = (q ->score[0] +q ->score[1] + q ->score[2] +q ->score[3]
    + q ->score[4])/5.0;
    fp_in = fopen("stu-sort","r+");
    for(i = 0;i < SIZE;i++)
    {
    fscanf(fp_in,"%d%f",&stu[i].num,&stu[i].aver);
    //printf("fuck %f\n",stu[i].aver);
    //stu_aver[i] = stu[i].aver;
    }
    //for(i = 0;i < SIZE;i++)
    //printf("%f\n",stu[i].aver);
    //printf("%f\n",q ->aver);
    head ->next = &stu[0];
    for(i = 0;i < SIZE;i++)
    {
    if(i <= SIZE - 2)
    stu[i].next = &stu[i + 1];
    else
    stu[i].next = NULL;
    }
    p = head;
    if(q ->aver <= stu[0].aver)
    {
    p ->next = q;
    q ->next = &stu[0];
    }
    else if(q ->aver >= stu[SIZE - 1].aver)
    {
    stu[SIZE - 1].next = q;
    q ->next = NULL;
    }
    else
    {
    for(i = 0;i < SIZE - 1;i++)
    {
    if((q ->aver > stu[i].aver) && (q ->aver < stu[i + 1].aver))
    {
    stu[i].next = q;
    q ->next = &stu[i + 1];
    }
    }
    }
    fclose(fp_in);
    fp_new = fopen("new","w+");
    p = head ->next;
    for(;;)
    {
    fprintf(fp_new,"%d\n",p ->num);
    fprintf(fp_new,"%s\n",p ->name);
    fprintf(fp_new,"%s\n",p ->sex);
    fprintf(fp_new,"%d %d %d %d %d\n",p ->score[0],p ->score[1],p ->score[2],
    p ->score[3],p ->score[4]);
    fprintf(fp_new,"%lf\n",p ->aver);
    p = p ->next;
    if(p == NULL)
    break;
    }
    fclose(fp_new);
    
    }
    
    void search()
    {
    int i;
    p = head ->next;
    for(;;)
    {
    for(i = 0;i < 5;i++)
    {
    if(p ->score[i] < 60)
    {
    printf("%d\n",p ->num);
    printf("%s\n",p ->name);
    printf("%s\n",p ->sex);
    printf("%d %d %d %d %d\n",p ->score[0],p ->score[1],p ->score[2],
    p ->score[3],p ->score[4]);
    printf("%lf\n",p ->aver);
    break;
    }
    }
    if(p ->aver >= 90)
    {
    printf("%d\n",p ->num);
    printf("%s\n",p ->name);
    printf("%s\n",p ->sex);
    printf("%d %d %d %d %d\n",p ->score[0],p ->score[1],p ->score[2],
    p ->score[3],p ->score[4]);
    printf("%lf\n",p ->aver);
    }
    p = p ->next;
    if(p == NULL)
    break;
    }
    }
    
    int main(void)
    {
    //FILE *fp;
    //int i,j;
    save();
    sort();
    add();
    printf("\n");
    search();
    return 0;
    }
    2019-07-17 19:10:32
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
视频内容理解的研究与实践 立即下载
长安十二时辰背后的技术秘籍 立即下载
WEB框架0day漏洞的发掘及分析经验分享 立即下载