C語言可變參數(shù)函數(shù)使用總結(jié)
//ADS1.2下編譯使用
void TestFun(char* fmt,...)
{
int ch;
char selch = 0;
va_list ap = NULL;
va_start(ap, fmt);
do
{
selch = *fmt;
if (selch!='%')
{
putchar(*fmt);
}
else
{
selch = *++fmt;
switch(selch)
{
case 'c':
ch = va_arg(ap, int);
printf("%c",ch);
break;
case 'd':
ch = va_arg(ap,int);
printf("%d",ch);
break;
case 'x':
ch = va_arg(ap, int);
printf("%#x",ch);
break;
}
}
++fmt;
}while(*fmt!='');
va_end(ap);
}
//調(diào)用
TestFun((char*)"this is %d,%c,%x",1234,'6',0x12345);
//WIN-TC編譯通過
#i nclude
/************************************************************
typedef void *va_list;
#define va_start(ap, parmN) (ap = ...)
#define va_arg(ap, type) (*((type *)(ap))++)
#define va_end(ap)
***************************************************/
void TestFun(cosnt char* fmt,...)
{
int ch;
long i32value = 0;
char selch = 0;
va_list ap = 0;
va_start(ap, fmt);
評(píng)論