- void param_demo(char *fmt, )
- {
- int param_count, i;
- char *pi;
- param_count = (int)strlen(fmt);
- pi = (char *)&fmt + sizeof(char *);
- for (i=0; i < param_count; i++)
- {
- switch(fmt[i])
- {
- case 'i':
- printf("int : %d \\n", *((int *)pi));
- pi = pi + sizeof (int);
- break;
- case 's':
- printf("string : %s \\n", *((char **)pi));
- pi = pi + sizeof (char *);
- break;
- case 'c':
- printf("char : %c \\n", *pi);
- pi = pi + sizeof (int);
- break;
- case 'd':
- printf("double : %lf \\n", *((double *)pi));
- pi = pi + sizeof (double);
- break;
- default:
- break;
- }
- }
- }
- /*这个函数可以这样调用:
- param_demo("idsc", 2, 2.01, "hello, world", 'c');
- 然后将会输出:
- int : 2
- double : 2.010000
- string : hello, world
- char : c*/
- //该片段来自于http://www.codesnippet.cn/detail/280120131951.html
来源: http://www.codesnippet.cn/detail/280120131951.html