快捷搜索:

您的位置:澳门新葡4473网站 > 新闻社区 > 大家帮我看看这个程序

大家帮我看看这个程序

发布时间:2020-01-24 18:28编辑:新闻社区浏览(89)

    #include "stdio.h"
    #include "conio.h"

    文件内容读出为链表,求教,和文件内容不一样啊 50C
    #include
    #include
    #include
    int n1,n2;
    struct stu{
    int num;
    char name[20];
    float score[6];
    float sum;
    float ave;
    struct stu next;
    };
    struct stu
    readfile{
    struct stu *p,*q,*top;
    char name[20];
    int num,i;
    float sum,ave,score[6];
    FILE *pc;
    if((fp=fopen("www.txt","r"))==NULL){
    printf("File open error!");
    exit;
    }
    top=(struct stu)malloc(sizeof(struct stu));
    fscanf(fp,"%-10d%-20s",&(top->num),&(top->name));
    for(i=0;i fscanf(fp,"%-10.1f",&top->score[i]);
    }
    fscanf(fp,"%-10.1f%-10.1f",&top->sum ,&top->ave );
    q=top;
    while){
    p=(struct stu
    )malloc(sizeof(struct stu));
    fscanf(fp,"%-10d%-20s",&(p->num),&(p->name));
    for(i=0;i fscanf(fp,"%-10.1f",&p->score[i]);
    }
    fscanf(fp,"%-10.1f%-10.1f",&p->sum ,&p->ave );
    p->next=NULL;
    q->next=p;
    q=p;
    }
    return top;
    }图片 1

    #define NULL 0

    typedef struct course
       {
          char cour[30];
          char score;
          char teacher[10] ;
          struct corse *next;
        }COURSE;

    typedef struct student
       {
              int num;
              char name[10];
              char dep[20];
              float ave;
              COURSE *link;
              struct  student *next;
        }STUDENT;

      COURSE *creatCourseNode()
         {
             COURSE *p=(COURSE *)malloc(sizeof(COURSE));
             scanf("%s%s%s",p->cour,p->teacher,p->score);
             if(p->score==-1)
              {
                 free(p);
                 return NULL;
              }
              else
                 return p;
         }

     void insertCourseNode(COURSE **h,STUDENT *couRse)
        {
          COURSE *p,*q;
          if((*h)==NULL||couRse->score==(*h)->score)
            {
                couRse->next=*h;
                *h=couRse;
            }
           else
              {
                 q=*h;
                 p=q->next;

                 while((p!=NULL)&&(couRse->score<vp->next))
                   {
                      q->next=couRse;
                      p=p->next;
                   }
                   couRse->next=p;
                   q->next=couRse;
              }
        }

      float aver(COURSE *link)
         {
             int n=0,total=0;
             while(link!=NULL)
               {
                  total+=link->score;
                  n++;
                  link=link->next;
                  if(n)
                   {
                     return (float)total/n;
                   }
                  else
                    return 0.0;
               }
         }

      STUDENT *creatStudentNode()
         {
           COURSE *q;
           STUDENT *p=(STUDENT *)malloc(sizeof(STUDENT));
           scanf("%d%c%s",&p->num,p->name,p->dep);
           while((q=creatCourseNode())!=NULL)
             {
                insertCourseNode(&(p->link),q);
                p->ave=aver(p->link);
                return p;
             }
         }

     void insertStudentNode(STUDENT **h,STUDENT *stu)
        {
            STUDENT *p,*q;
            if((*h)==NULL||(*h)->ave==stu->ave)
              {
                 stu->next=*h;
                 *h=stu;
              }
              else
                 {
                    q=*h;
                    p=q->next;
                    while (p!=NULL&&stu->ave<p->ave)
                     {
                         q=p;
                         p=p->next;
                         stu->next=p;
                         q->next=stu;
                     }
                 }
        }

     int main(int argc ,char *argv[])
       {
          int n=0,i;
          STUDENT *head=NULL,*ptr;
          COURSE *p,*q;
          scanf("%d",&n);
          for(i=0;i<n;i++)
            {
               printf("%d%s%f",&head->num,&head->name,&head->dep,&head->ave);
               p=head->link;
               while(p!=NULL)
                {
                   printf("%s%d%s",&p->cour,&p->score,&p->teacher);
                   q=p;
                   p=p->next;
                }
                free(q);
            }
            ptr=head;
            head=head->next;
            free(ptr);
         return 0;
       }

     

    怎么得不到结果?

    本文由澳门新葡4473网站发布于新闻社区,转载请注明出处:大家帮我看看这个程序

    关键词: