어허

function pointer 본문

개발/C(C++)

function pointer

AKDK 2012. 6. 20. 15:25
728x90

   
typedef struct {
	BYTE command[32];
	void (*set)(BYTE *);
	BYTE hidden;
	BYTE usage[128];
}Fp;

code Fp fn_cli[] = {
	{"show all",			show_all_config,		ON,		" show all                     : can you see all config",			},
}

void main(){
        // cmd_string input...
	for(i=0;i<( sizeof(fn_cli) / sizeof(fn_cli[0]) );i++){
		if(!strncmp(cmd_string, fn_cli[i].command, strlen(fn_cli[i].command))){
			argv[1]=&(*cmd_string)+strlen(fn_cli[i].command)+1;
		 	fn_cli[i].set(argv[1]);
		}
	}
}

이거 처음 알고 썼을때 완전 신세경 @_@
완전 편함
정리하면, 입력받는 루틴엥서 "show all"이란 명령이 들어오면 배열 비교해서 같은 글씨 있나 확인하고
같으면 struct의 function pointer 부분의 함수 show_all_config 함수 호출,
끝!
728x90
"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."
공유하기 링크
Comments