C语言程序错误cannot convert parameter 3 from 'struct student [2][2]' to 'struct stu [][2]
具体错误显示出现在main函数中case'd'里的第二行怎么改呢#include<stdio.h>#include<stdlib.h>#include<time.h>#d...
具体错误显示出现在main函数中case'd'里的第二行 怎么改呢
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define P 2
#define Q 2
struct student
{
int score[5];
char number[11];
char name[7];
float average;
};
struct node
{
int x,y;
struct node *next;
};
void input(int i,int j,struct student stu[P][Q]);
void output(int i, int j,struct student stu[P][Q]);
void sort1(struct student a[P][Q],int b);
void sort2(struct student a[P][Q],int b);
void meun(void);
void random(int c[P][Q],struct student stu[P][Q]);
struct node *list(int c[P][Q],struct node*p1,struct stu[][Q]);
void out(struct node *L,struct student stu[P][Q]);
void main()
{
int i,j,n;
struct node *p1=NULL;
struct student stu[P][Q];
for(i=0;i<P;i++)
for(j=0;j<Q;j++)
{
input(i,j,stu);
}
while(getchar()!='\n')
meun();
while(1)
{
switch(getchar())
{
case'a':
{
int c[P][Q]={0};
random(c,stu);
}
break;
case'b':
printf("Input number of class:");
scanf("%d",&n);
sort1(stu,n);
for(j=0;j<Q;j++)
output(n,j,stu);
break;
case'c':
printf("Input number of class:");
scanf("%d",&n);
sort2(stu,n);
for(j=0;j<Q;j++)
output(n,j,stu);
break;
case'd':
{
int c[P][Q]={0};
p1=list(c,p1,stu);
out(p1,stu);
}
break;
case'e':exit(0);
default:
printf("Error");
}
while(getchar()!='\n');
}
}
void input(int i,int j,struct student stu[P][Q])
{
printf("Input the name:");
scanf("%s",&stu[i][j].name);
printf("input the number:");
scanf("%s",&stu[i][j].number);
int k,n;
stu[i][j].average=0;
printf("Input the score:\n");
for(k=0;k<5;k++)
{
while(scanf("%d",&n)==1)
{
if(n<0||n>100)
{
printf("An error has occured,plz enter again:");
continue;
}
else
{
stu[i][j].score[k]=n;
stu[i][j].average+=stu[i][j].score[k];//a+=c ==a=a+c
break;
}
}
}
stu[i][j].average/=5.0;//a/=b ==a=a/b
}
void output(int i,int j,struct student stu[][Q])
{
int x;
printf("%-11s %-5s",stu[i][j].number,stu[i][j].name);
for(x=0;x<5;x++)
{
printf("%-4d",stu[i][j].score[x]);
}
printf("%f\n",stu[i][j].average);
}
void sort1(struct student a[][Q],int b)
{
int i,j;
float temp;
for(i=Q;i>0;i--)
for(j=1;j<i;j++)
{
if(a[b][j-1].average<a[b][j].average)
{
temp=a[b][j-1].average;
a[b][j-1].average=a[b][j].average;
a[b][j].average=temp;
}
}
}
void sort2(struct student a[][Q],int b)
{
int i,j,h;
float temp;
for(i=0;i<Q-2;j++)
{
h=i+1;
for(j=i+1;j<Q-1;j++)
{
if(a[b][j].average<a[b][j+1].average)
h=j+1;
}
if(a[b][i].average<a[b][h].average)
{
temp=a[b][i].average;
a[b][i].average=a[b][h].average;
a[b][h].average=temp;
}
}
}
后面程序略 展开
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define P 2
#define Q 2
struct student
{
int score[5];
char number[11];
char name[7];
float average;
};
struct node
{
int x,y;
struct node *next;
};
void input(int i,int j,struct student stu[P][Q]);
void output(int i, int j,struct student stu[P][Q]);
void sort1(struct student a[P][Q],int b);
void sort2(struct student a[P][Q],int b);
void meun(void);
void random(int c[P][Q],struct student stu[P][Q]);
struct node *list(int c[P][Q],struct node*p1,struct stu[][Q]);
void out(struct node *L,struct student stu[P][Q]);
void main()
{
int i,j,n;
struct node *p1=NULL;
struct student stu[P][Q];
for(i=0;i<P;i++)
for(j=0;j<Q;j++)
{
input(i,j,stu);
}
while(getchar()!='\n')
meun();
while(1)
{
switch(getchar())
{
case'a':
{
int c[P][Q]={0};
random(c,stu);
}
break;
case'b':
printf("Input number of class:");
scanf("%d",&n);
sort1(stu,n);
for(j=0;j<Q;j++)
output(n,j,stu);
break;
case'c':
printf("Input number of class:");
scanf("%d",&n);
sort2(stu,n);
for(j=0;j<Q;j++)
output(n,j,stu);
break;
case'd':
{
int c[P][Q]={0};
p1=list(c,p1,stu);
out(p1,stu);
}
break;
case'e':exit(0);
default:
printf("Error");
}
while(getchar()!='\n');
}
}
void input(int i,int j,struct student stu[P][Q])
{
printf("Input the name:");
scanf("%s",&stu[i][j].name);
printf("input the number:");
scanf("%s",&stu[i][j].number);
int k,n;
stu[i][j].average=0;
printf("Input the score:\n");
for(k=0;k<5;k++)
{
while(scanf("%d",&n)==1)
{
if(n<0||n>100)
{
printf("An error has occured,plz enter again:");
continue;
}
else
{
stu[i][j].score[k]=n;
stu[i][j].average+=stu[i][j].score[k];//a+=c ==a=a+c
break;
}
}
}
stu[i][j].average/=5.0;//a/=b ==a=a/b
}
void output(int i,int j,struct student stu[][Q])
{
int x;
printf("%-11s %-5s",stu[i][j].number,stu[i][j].name);
for(x=0;x<5;x++)
{
printf("%-4d",stu[i][j].score[x]);
}
printf("%f\n",stu[i][j].average);
}
void sort1(struct student a[][Q],int b)
{
int i,j;
float temp;
for(i=Q;i>0;i--)
for(j=1;j<i;j++)
{
if(a[b][j-1].average<a[b][j].average)
{
temp=a[b][j-1].average;
a[b][j-1].average=a[b][j].average;
a[b][j].average=temp;
}
}
}
void sort2(struct student a[][Q],int b)
{
int i,j,h;
float temp;
for(i=0;i<Q-2;j++)
{
h=i+1;
for(j=i+1;j<Q-1;j++)
{
if(a[b][j].average<a[b][j+1].average)
h=j+1;
}
if(a[b][i].average<a[b][h].average)
{
temp=a[b][i].average;
a[b][i].average=a[b][h].average;
a[b][h].average=temp;
}
}
}
后面程序略 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询