小白求助
#include<stdio.h>#include<string.h>
structcandicate
{
char name;
int count;
};
void function(struct candicate c[],int n);
int main()
{
structcandicatec[] = {{"chen",0},{"he",0},{"wang",0}};
int i,j,n;
char name;
printf("参与投票的人数:");
scanf("%d",&n);
for(i = 0;i < n;i++)
{
printf("第%d人投的是:",i+1);
scanf("%s",name);
for(j = 0;j < 3;j++)
{
if(strcmp(c.name,name)== 0)
{
c.count++;
}
}
}
for(i = 0;i < 3;i++)
{
function(c,n);
printf("第%d位候选人\"%s\"的投票数为%d\n",i+1,c.name,c.count);
}
return 0;
}
void function(struct candicate c[],int n)
{
int a,b;
struct candicate temp;
for(a = 0;a < n - 1;a++)
{
for(b = 0;b < n - 1 - a;b++)
{
if((c.count < c.count)|| (c.count = c.count && strcmp(c.name,c.name) > 0))
{
temp = c;
c = c;
c = temp;
}
}
}
}
有大佬帮我看看这段代码哪里错了吗? 第 37 行错误,function(c[], i);// 出现不存在从 "candicate" 到 "candicate *" 的适当转换函数
#include<stdio.h>
#include<string.h>
structcandicate
{
char name;
int count;
};
void function(struct candicate c[], int n);
int main()
{
structcandicatec[] = { {"chen",0},{"he",0},{"wang",0} };
int i, j, n;
char name;
printf("参与投票的人数:");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("第%d人投的是:", i + 1);
scanf("%s", name);
for (j = 0; j < 3; j++)
{
if (strcmp(c.name, name) == 0)
{
c.count++;
}
}
}
for (i = 0; i < 3; i++)
{
function(&c, n); // 加上了 &
printf("第%d位候选人\"%s\"的投票数为%d\n", i + 1, c.name, c.count);
}
return 0;
}
void function(struct candicate c[], int n)
{
int a, b;
struct candicate temp;
for (a = 0; a < n - 1; a++)
{
for (b = 0; b < n - 1 - a; b++)
{
if ((c.count < c.count) || (c.count = c.count && strcmp(c.name, c.name) > 0))
{
temp = c;
c = c;
c = temp;
}
}
}
}
页:
[1]