结构指针型函数

来源:互联网 发布:c语言中文网官网 编辑:程序博客网 时间:2024/06/18 05:06
#include <iostream>#include<string>using namespace std;struct sample{    int num;    char color;    char type;}car[] = {101,'G','c',201,'Y','m',105,'R','i',222,'B','s',308,'P','b',0,0,0};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<<"number:"<<result->num<<endl;        cout<<"color:"<<result->color<<endl;        cout<<"type:"<<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];}

0 0
原创粉丝点击