结构指针返回问题
#include<iostream.h>#define null 0
struct sample //结构体
{ int num;
char color;
char type;
};
struct sample car[4]={{101,'g','c'},{210,'y','m'},{105,'r','t'},{0,0,0}}; //4个数据
struct sample *find(int n);
void main()
{ int number;
struct sample *result;
cout<<"enter the number:";
cin>>number;
result=find(number);
if (result->num!=null)
{ cout<<result->num<<endl;
cout<<result->color<<endl;
cout<<result->type<<endl;
}
else
cout<<"not found"<<endl;
}
struct sample *find(int n)
{
int i;
for(i=0;car[i].num!=null;i++)
if(car[i].num=n)
break;
return(&car[i]); //这里我返回的就是地址啊``郁闷- -
};
请大家帮我看一下,为什么我输入数字后,数字能和预先定义的相同,但后面2个字符就永远是g,c(第一个数据的值)