结构体问题:为什么运行结果会出现“] 0 - ”这么奇怪的东西?
源程序:#include<stdio.h>
#include"string.h"
struct
{
char name[20];
int count;
}can[3]={{"wang",0},{"ling",0},{"ming",0}};
void main()
{
int i,j;
char name[20];
for(i=0;i<5;i++)
{
printf("please input the name:");
scanf("%s",name);
for(j=0;j<3;j++)
{
if(strcmp(name,can[j].name)==0)
can[j].count++;
}
}
printf("\n");
for(j=0;j<=3;j++)
printf("%s %d\n",can[j].name,can[j].count);
}
运行结果:
please input the name:wang
please input the name:ling
please input the name:ling
please input the name:ling
please input the name:ming
wang 1
ling 3
ming 1
] 0 -
Press any key to continue