c语言,想用结构体变量数组输入十个职员职工号和姓名,再用起泡法排序
#include<stdio.h>struct person
{
int number;
char name;
};
int main()
{
struct person staff,*p=staff;
void max(struct person staff[]);
void xuan(struct person staff[],int n);
int c;
for(c=0;c<10;c++)
{
printf("请输入他的职工号\n");
scanf("%d",&staff.number);
printf("请输入他的姓名\n");
scanf("%s",staff.name);
}
max(p);
}
max(struct person staff[])
{
int i,j,k,n,q;
for(i=0;i<9;i++)
for(j=0;j<9-i;j++)
{
if(staff.number>staff.number)
{
q=staff.number;
staff.number=staff.number;
staff.number=q;
}
}
for(k=0;k<10;k++)
printf("%d%s\n",&staff.number,staff.name);
scanf("%d",&n);
xuan(p,n);
}
xuan(struct person staff[],int h)
{
int mid,high,low,g;
high=9;low=0;
while(high>=low)
{
mid=(low+high)/2;
if(staff.number==h)
{
g=1;
break;
}
if(staff.number>h)
high=mid-1;
if(staff.number<h)
low=mid+1;
if(low>high)
{
g=0;
break;
}
}
if(g==1)
printf("%d%s ",&staff.number,staff.name);
if(g==0)
printf("无效数字,请重新输入!");
getchar();
scanf("%d",&h);
xuan(p,h);
}
c语言,想用结构体变量数组输入十个职员职工号和姓名,再用起泡法排序,再输入一个职工号,再用二分法选取,在输出,如没找到,再重新输入。
出现了好多问题,error C2371: 'max' : redefinition; different basic types
D:\123\5\5.c(10) : see declaration of 'max'
D:\123\5\5.c(37) : error C2065: 'n' : undeclared identifier
D:\123\5\5.c(38) : error C2065: 'p' : undeclared identifier
D:\123\5\5.c(38) : warning C4047: 'function' : 'struct person *' differs in levels of indirection from 'int '
D:\123\5\5.c(38) : warning C4024: 'xuan' : different types for formal and actual parameter 1
D:\123\5\5.c(41) : error C2371: 'xuan' : redefinition; different basic types
D:\123\5\5.c(11) : see declaration of 'xuan'
执行 cl.exe 时出错.
5.exe - 1 error(s), 0 warning(s)
已经知道;谢谢大家了
页:
[1]