我是靠谱客的博主 舒适白羊,最近开发中收集的这篇文章主要介绍在vc6编译代码时出现error C2120: 'void' illegal with all types,请教大神该怎么改?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include<stdio.h>                            //头文件的开始

#include<stdlib.h>

struct Student1                                //学生结构体

{

      long int number;

      char name[15],sex[5];

      int age;

      float score[4];

      double total;

      double averge;

};

struct Student                                  //结点结构体

{

    struct Student1 stu;

      struct Student *next;

};

void Caidan(struct Student *p);                     //菜单函数

int print();                                      //主菜单输出函数

void Input(struct Student *p);                      //数据输入函数

void Insert(struct Student *p);                      //插入函数

void Sort(struct Student *p);                       //排序总函数

void Sort1(struct Student *p);                      //学号排序函数

void Sort2(struct Student *p);                      //成绩排序函数

void Find(struct Student *p);                      //查找函数

void Delet(struct Student *p);                      //删除函数

void Display(struct Student *p);                    //从函数中读取输出函数

void Display1(struct Student *p);                   //输出函数

void out();                                     //退出函数

void Write(struct Student *,char s[]);                //写函数

void Read(struct Student *,char s[]);                //读函授

/*主函数开始*/

int main()

{   struct Student *p=NULL;                     //定义结点指针             

      for(;;)                                     //死循环控制菜单

             Caidan(p);

      return 0;

}                                            //主函数结束

void Caidan(struct Student *p)          //菜单函数

{  int n;

      n=print();                                  //调用菜单输出函数

      switch(n)                                  //用switch做菜单选择

      {

      case 1: Input(p);break;                       //输入1调用Input函数

      case 2:Insert(p);break;                       //输入2调用Insert函数

      case 3: Sort(p);break;                        //输入3调用Sort函数

      case 4:Find(p);break;                        //输入4调用Find函数

      case 5:Delet(p);break;                       //输入5调用Delet函数

      case 6:Display(p);break;                     //输入6调用Display函数

      case 7:out();break;                          //输入7调用Out函数

      }

}                                          //菜单函数结束                                                                           

int print()                                    //菜单输出函数

{

      int n;

      printf("********************目录**********************n");

      printf("**                 1.输入                   **n");

      printf("**                 2.插入                  **n");

      printf("**                 3.排序                   **n");

      printf("**                 4.查找                   **n");

      printf("**                 5.删除                   **n");

      printf("**                 6.输出                   **n");

      printf("**                 7.退出                   **n");

      printf("**********************************************n");

      printf("请从1--7选择:");

      scanf("%d",&n);

      return n;

}

void Input(struct Student *p)      //数据输入函数

{   int count=0,N;              //定义计数器count和要输入的学生个数变量N                                           

      struct Student *a;

      printf("请输入要录入的学生个数");

      scanf("%d",&N);

      printf("请输入学号、姓名、性别、年龄和四科成绩n");

      for(count=0;count<N;count++)  //用循环来控制内存空间的分配,并录入数据         

      {   if(count==0)

                    a=p=calloc(1,sizeof(structStudent));  

             if(count!=0)

             {  p->next=calloc(1,sizeof(struct Student));

                    p=p->next;

             }

             if(count==N-1)

                    p->next=NULL;

             scanf("%ld %s %s %d%f%f%f%f",&p->stu.number,p->stu.name,p->stu.sex,

&p->stu.age,&p->stu.score[0],&p->stu.score[1],&p->stu.score[2],&p->stu.score[3]);

      p->stu.total=p->stu.score[0]+p->stu.score[1]+p->stu.score[2]+p->stu.score[3];

             p->stu.averge=p->stu.total/4.0;

      }

      Sort1(a);                                    //调用排序函数

      Write(a,"stu.dat");                            //调用写入函数

}                                             //数据输入函数结束

void Write(struct Student *p,char s[])                //文件写入函数

{   FILE *fp;

      struct Student *a;

      if((fp=fopen(s,"wb"))==NULL)               //以二进制写的方式打开文件

      {   printf("error!!");

             exit(0);

      }

      do

      {   if(fwrite(p,sizeof(struct Student),1,fp)!=1)

                    printf("writeerror!!");

             a=p;

             p=p->next;

             free(a);                               //内存释放

      }while(p!=NULL);

      fclose(fp);                                //关闭文件

}                                           //文件的写函数结束

void Read(struct Student *p,char s[])             //文件的读函数

{  FILE *fp;

      struct Student *a,*b;

      if((fp=fopen(s,"rb"))==NULL)               //以二进制读的方式打开文件

      {   printf("read open error!");

             exit(0);

      }

      a=p=calloc(1,sizeof(structStudent));          //分配内存空间

      do

      {   if(fread(p,sizeof(structStudent),1,fp)!=1)   //读到内存

                  printf("read error!!");

             b=p->next;

             if(b!=NULL)

             {   p->next=calloc(1,sizeof(struct Student));

                 p=p->next;

             }

      }while(b!=NULL);

}                                            //结束

void Display(struct Student *p)                    //从文件中读并输出到文件

{   struct Student *a;

      p=Read(p,"stu.dat");

      printf("学号  姓名   性别  年龄  高数   语文    英语    体育     总成绩    平均成绩n");

      do

      {printf("%-5ld  %-5s %-5s  %-4d %-4.2f %-4.2f   %-4.2f    %-4.2f   %-4.2lf   %-4.2lfn",p->stu.number,p->stu.name,

p->stu.sex,p->stu.age,p->stu.score[0],p->stu.score[1],p->stu.score[2],p->stu.score[3],p->stu.total,p->stu.averge);

             a=p;

             p=p->next;

             free(a);

      }while(p!=NULL);

}                                            //文件结束

void Display1(struct Student *p)                   //输出函数

{   struct Student *a;

      printf("学号  姓名   性别  年龄  高数   语文    英语    体育     总成绩    平均成绩n");

      do

      {     printf("%-5ld %-5s  %-5s  %-4d %-4.2f  %-4.2f  %-4.2f    %-4.2f   %-4.2lf   %-4.2lfn",p->stu.number,p->stu.name,

p->stu.sex,p->stu.age,p->stu.score[0],p->stu.score[1],p->stu.score[2],p->stu.score[3],p->stu.total,p->stu.averge);

             a=p;

             p=p->next;

      }while(p!=NULL);

}                                              //函数结束

void Insert(struct Student *p)                       //插入函数

{   int n,i,count;

      struct Student *a,*c,*t,*head;

      printf("请输入要插入学生的个数:");

      scanf("%d",&n);

      head=Read(p,"stu.dat");

      for(i=0;i<n;i++)

      { a=calloc(1,sizeof(structStudent));

        scanf("%ld %s %s %d %f %f %f%f",&a->stu.number,a->stu.name,a->stu.sex,

&a->stu.age,&a->stu.score[0],&a->stu.score[1],&a->stu.score[2],&a->stu.score[3]);

      a->stu.total=a->stu.score[0]+a->stu.score[1]+a->stu.score[2]+a->stu.score[3];

             a->stu.averge=a->stu.total/4.0;

             a->next=NULL;

             count=0;

             p=head;

             do

             {  if(a->stu.number<p->stu.number)

                    {  if(count==0)

                           {  a->next=p;

                                  head=a;

                           }

                           else

                           {   t=c->next;

                                  c->next=a;

                                  a->next=t;

                           }

                           break;

}

                    c=p;

                    p=p->next;

                    count++;

             }while(p!=NULL);

             if(p==NULL)

             {   c->next=a;

                    a->next=NULL;

             }

      }

      Display1(head);

      Write(head,"stu.dat");

}                                  //函数结束             

void Sort1(struct Student *p)            //学号排序     

{

      int n=0,i,j;

      struct Student1 t;

      struct Student *p1,*a;

      a=p;

      do

      {  p=p->next;

             n++;

      }while(p!=NULL);

      p=a;

      for(i=0;i<n-1;i++)

      {   p=a;

             for(j=0;j<n-1-i;j++)

             {   p1=p->next;

                    if(p->stu.number>p1->stu.number)

                    {   t=p->stu;

                           p->stu=p1->stu;

                           p1->stu=t;

                    }

                    p=p1;

             }

      }

}

void Sort2(struct Student *p)            //按成绩排序函数

{   int n=0,i,j;

      struct Student1 t;

      struct Student *p1,*a;

      a=Read(p,"stu.dat");

      p=a;

      do

{   p=p->next;

             n++;

      }while(p!=NULL);

      p=a;

      for(i=0;i<n-1;i++)

      {   p=a;

             for(j=0;j<n-1-i;j++)

             {   p1=p->next;

                    if(p->stu.total>p1->stu.total)

                    {   t=p->stu;

                           p->stu=p1->stu;

                           p1->stu=t;

                    }

                    p=p1;

             }

      }

      Display1(a);

}                                              //函数结束

void Sort(struct Student *p)                         //总排序函数

{   printf("按学号排序:n");

      Display(p);

      printf("按总成绩排名:n");

      Sort2(p);

}

void out()                                       //退出函数

{exit(0);}                                       //函数结束

void Find(struct Student *p)                        //查找函数

{  long int num;

      int n=0;

      struct Student *a;

      p=Read(p,"stu.dat");

      printf("请输入要查询的学号:");

      scanf("%ld",&num);

      do

      {if(num==p->stu.number)

      {printf("学号 姓名 性别 年龄 高数 语文 英语 体育 总成绩 平均成绩n");

       printf("%-5ld%-5s %-5s %-4d %-4.2f %-4.2f %-4.2f%-4.2f %-4.2lf    %-4.2lfn",p->stu.number,p->stu.name,

p->stu.sex,p->stu.age,p->stu.score[0],p->stu.score[1],p->stu.score[2],p->stu.score[3],p->stu.total,p->stu.averge);

                    n=1;}

             a=p;

             p=p->next;

          free(a);

      }while(p!=NULL);

      if(n==0)

             printf("没有你要查找的学生信息。n");

}

void Delet(struct Student *p)

{  long int num;

      int n=0;

      struct Student *a,*head;

      head=p=Read(p,"stu.dat");

      printf("请输入要删除学生的学号:");

      scanf("%ld",&num);

      do

      {  if(num==p->stu.number)

             {  if(n==0)

                    {   head=p->next;

                           free(p);

                           break;

                    }

                    else

                    {   a->next=p->next;

                           free(p);

                           break;

                    }

             }

             a=p;

             p=p->next;

      }while(p!=NULL);

      Display1(head);

      Write(head,"stu.dat");}

最后

以上就是舒适白羊为你收集整理的在vc6编译代码时出现error C2120: 'void' illegal with all types,请教大神该怎么改?的全部内容,希望文章能够帮你解决在vc6编译代码时出现error C2120: 'void' illegal with all types,请教大神该怎么改?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部