C语言这样写,为什么会报错?求大神指教!
#include<stdio.h>#include<string.h>structPerson{charname[20];intcount;}leader[3]={"LI...
#include <stdio.h>
#include <string.h>
struct Person
{
char name[20];
int count;
}leader[3] = {"LI", 0, "Zhang", 0, "Sun", 0};
int main()
{
int i, j;
char leader_name[20];
for (i = 1; i <= 10; i ++)
{
scanf ("%s", leader_name);
for (j = 0; j < 3; j ++)
{
if (strcmp(leader_name, leader[j].name == 0))
{
leader[j].count ++;
}
}
}
printf ("\nResult:\n");
for (i = 0; i < 3; i ++)
{
printf ("%5s:%d\n", leader[i].name, leader[i].count);
}
return (0);
}
报错提示:
D:\0001\0002\Noname1.c(21) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\0001\0002\Noname1.c(21) : warning C4024: 'strcmp' : different types for formal and actual parameter 2 展开
#include <string.h>
struct Person
{
char name[20];
int count;
}leader[3] = {"LI", 0, "Zhang", 0, "Sun", 0};
int main()
{
int i, j;
char leader_name[20];
for (i = 1; i <= 10; i ++)
{
scanf ("%s", leader_name);
for (j = 0; j < 3; j ++)
{
if (strcmp(leader_name, leader[j].name == 0))
{
leader[j].count ++;
}
}
}
printf ("\nResult:\n");
for (i = 0; i < 3; i ++)
{
printf ("%5s:%d\n", leader[i].name, leader[i].count);
}
return (0);
}
报错提示:
D:\0001\0002\Noname1.c(21) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\0001\0002\Noname1.c(21) : warning C4024: 'strcmp' : different types for formal and actual parameter 2 展开
1个回答
2016-07-01
展开全部
if (strcmp(leader_name, leader[j].name == 0))
改成
if (strcmp(leader_name, leader[j].name) == 0)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询