次のプログラムの赤字の部分に入るべきコードは何でしょうか?
#include <stdio.h> #include <stdlib.h> static const char *a(void); static const char *b(void); static void CallFuncs( const char *pcTrigger ); typedef struct { int m_nCh; /* ここに入るべきコードは何か? */ } FunctionMap; static FunctionMap fs_pMap[] = { { 'a', a }, { 'b', b }, { -1, 0 } }; int main(void) { CallFuncs( "abaababb" ); return EXIT_SUCCESS; } static void CallFuncs( const char *pcTrigger ) { const char *pc = pcTrigger; for ( ; *pc!='\0'; pc++ ) { const FunctionMap *pMap = fs_pMap; for ( ; pMap->m_nCh!=-1; pMap++ ) { if ( pMap->m_nCh == *pc ) { puts( pMap->m_pFunc() ); break; } } } } static const char *a(void) { return "Called a()."; } static const char *b(void) { return "Called b()."; }
<< 問題一覧に戻る
(「C言語実力診断クイズ」は2001年5月から9月にかけて作成されたコンテンツです。)