|
>if((tbl[0].a == 指定a) && (tbl[0].b == 指定b)){
c = tbl[0].c;
}
上記をelse ifでつないでtbl[3]までやるのじゃだめだめだよね。
while()は?
この手のたぐいは基本的にfor()かwhile()でループらせる
のが基本なんだけど。
こんなのは?
#include <stdio.h>
typedef struct{
int a;
int b;
int c;
}ans;
const ans tbl[]={
{ 1, 2, 3},
{ 3, 4, 5},
{ 6, 7, 8},
{ 9, 10, 11 },
{ 0, 10, 11 }
};
int abc( const ans * ptr, int a, int b ){
if( ptr->a == 0 ){
return 0 ;
}
if( ptr->a == a && ptr->b == b ){
return ptr->c ;
}
return abc( ++ptr, a, b ) ;
}
int main( )
{
printf("%d\n",abc(tbl, 3, 4 )) ;
return 0 ;
}
|