为啥会有乱码呀,投票系统
#include<stdio.h>#include<stdlib.h>
#include<string.h>
struct person{
char name;
int score;
};
int main()
{
struct person person={"zhang",0,"li",0,"wang",0,"zhao",0,"liu",0,"zhu",0};
int i,j,k,score;
char name;
for(i=0;i<10;i++)
{
printf("请输入姓名:\n");
scanf("%s",name);
for(j=0;j<10;j++)
{
if(strcmp(name,person.name)==0)
{
person.score++;
}
}
}
for(i=0;i<10;i++)
{
printf("%s %d\n",person.name,person.score);
}
return 0;
} 本帖最后由 jackz007 于 2020-12-27 15:46 编辑
int main()
{
struct person person[6]={"zhang",0,"li",0,"wang",0,"zhao",0,"liu",0,"zhu",0};
. . . . . .
for(i=0;i<10;i++)
{
printf("%s %d\n",person[ i ].name,person[ i ].score);
}
结构数组下标越界,把红色的 10 改为 6 试试。
页:
[1]