先谢了,最好能给出一个例子。
解决方案 »
- 请教一个问题关于MFC控件的添加
- win32里 关于滚动条滚动图形+文字的问题
- 这个错误是什么意思?'__thiscall CFile::CFile(int)' : cannot convert parameter 1 from 'void *' to 'int'
- 我发送消息到某窗口,如何知道发送的消息是否被处理了!?
- 哪位大虾帮我看看这条语句,哪儿错了(在线)
- 散分!!顺便问一道C++类的题
- 计算机的 machine id 是指什么?
- 奇怪,用IE控件和ExecWB在自动打印中的应用问题??
- 近来在网上发了很多求教贴子,许多人都教我说:看看深入浅出就全懂了,好象他们很懂的样子。到底真懂假懂,到这里来分清!--120分求一例程,最先给出者得全分!!!
- 请问c语言的发展过程
- 网络安全公司诚邀您加盟!!
- 在系统上下文菜单中,调用函数GetUIObjectOf老是出错,为什么?
/* VA.C: The program below illustrates passing a variable
* number of arguments using the following macros:
* va_start va_arg va_end
* va_list va_dcl (UNIX only)
*/#include <stdio.h>
#define ANSI /* Comment out for UNIX version */
#ifdef ANSI /* ANSI compatible version */
#include <stdarg.h>
int average( int first, ... );
#else /* UNIX compatible version */
#include <varargs.h>
int average( va_list );
#endifvoid main( void )
{
/* Call with 3 integers (-1 is used as terminator). */
printf( "Average is: %d\n", average( 2, 3, 4, -1 ) ); /* Call with 4 integers. */
printf( "Average is: %d\n", average( 5, 7, 9, 11, -1 ) ); /* Call with just -1 terminator. */
printf( "Average is: %d\n", average( -1 ) );
}/* Returns the average of a variable list of integers. */
#ifdef ANSI /* ANSI compatible version */
int average( int first, ... )
{
int count = 0, sum = 0, i = first;
va_list er; va_start( er, first ); /* Initialize variable arguments. */
while( i != -1 )
{
sum += i;
count++;
i = va_arg( er, int);
}
va_end( er ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}
#else /* UNIX compatible version must use old-style definition. */
int average( va_alist )
va_dcl
{
int i, count, sum;
va_list er; va_start( er ); /* Initialize variable arguments. */
for( sum = count = 0; (i = va_arg( er, int)) != -1; count++ )
sum += i;
va_end( er ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}
#endif
#include <stdio.h>
//#include <varargs.h>int main( int argc, char **argv );
int printx( char *fmt, ... );#define NORMAL 0
#define TRUE 1
#define FALSE 0int
main( int argc, char **argv )
{
printx( "%s %d", "hello,world!", 234 );
return NORMAL;
}int
printx( char *fmt, ... )
{
va_list ap;
int d;
char c, *s; va_start( ap, fmt );
while (*fmt)
{
switch(*fmt++)
{
case 's': /* string */
s = va_arg(ap, char *);
printf("string %s\n", s);
break;
case 'd': /* int */
d = va_arg(ap, int);
printf("int %d\n", d);
break;
case 'c': /* char */
/* need a cast here since va_arg only
takes fully promoted types */
c = (char) va_arg(ap, int);
printf("char %c\n", c);
break;
default:
return FALSE;
}
}
va_end(ap);
return TRUE;
}
va_start
va_arg
va_end