strcmp 返回值的问题
#include <stdio.h>#include <string.h>
struct student
{
char name[20];
float score;
};
float Find(struct student *ff,char *fp);
int main()
{
struct student stu[5]={"zhangsan",56,"lisi",87,"wangwu",94,"zhaoliu",65,"sunqi",88};
char nam[20];
float i;
printf("请输入需要查询的学生的姓名:\n");
fgets(nam,20,stdin);
i=Find(stu,nam);
if(i<0)
printf("没有这个学生!\n");
else
printf("姓名:%10s 成绩:%3.1f\n",nam,i);
}
float Find(struct student *ff,char *fp)
{
int fp_i;
char fp_name[20];
for(fp_i=0;fp_i<strlen(fp);fp_i++)
fp_name[fp_i]=*(fp+fp_i);
for(fp_i=0;fp_i<5;fp_i++,ff++)
{
if(strcmp((ff->name),fp_name)==0)
return ff->score;
}
return -1;
}
查询的学生是wangwu
调试查看了ff->name和fp_name的值都是wangwu的时候,后面strcmp((ff->name),fp_name)的时候返回-1
那位大哥大姐能帮忙看一下哪里出了问题,谢谢了。