본문 바로가기

#include <stdarg.h>
#include <wtypes.h>

void VarArg(LPCSTR formatstring, ...)
{
int nSize = 0;
char buff[255];
va_list args;
va_start(args, formatstring);

nSize = _vsnprintf( buff, sizeof(buff), formatstring, args);
}

void main() {
VarArg("%s World", "Hello");
}

From. MSDN

mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2001OCT\1033\WCECRT.CHM::/htm/crt3_43.htm


______________________________________


/* 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 );
#endif

void 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 marker;

va_start( marker, first ); /* Initialize variable arguments. */
while( i != -1 )
{
sum += i;
count++;
i = va_arg( marker, int);
}
va_end( marker ); /* 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 marker;

va_start( marker ); /* Initialize variable arguments. */
for( sum = count = 0; (i = va_arg( marker, int)) != -1; count++ )
sum += i;
va_end( marker ); /* Reset variable arguments. */
return( sum ? (sum / count) : 0 );
}
#endif


Output

Average is: 3
Average is: 8
Average is: 0


From. MSDN

mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2001OCT\1033\vccore.chm::/html/_crt_va_arg.2c_.va_end.2c_.va_start.htm





번호 제목 날짜 조회 수
HOT [TIP] PYTHON 에서 "UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 6987: illegal multibyte sequence" 오류 날때... [52] 2016.02.20 266428
HOT [펌] ARM GCC Inline Assembler Cookbook 2006.08.18 57960
HOT [TIP] R에서 페이스북 페이지 정보 크롤링 하기 [6] 2017.02.11 39882
70 인터넷 익스플로러 툴바(툴밴드) 관련 소스링크 2003.07.23 651
» scanf, printf와 같이 다수의 파라메터 처리 방법(MSDN) 2003.08.20 655
68 PHP,ASP,PERL에서 파일사이즈 알아내는 방법(For GunClient...) 2003.05.30 877
67 CRC 체크 C 소스 입니다. 2003.03.24 2700
66 HTTP프로토콜을 이용한 파일 업로드 2002.12.24 3526
65 [Tip] CTRL-ALT-DEL키 막는법(NT,2000,XP,98) 2002.07.11 817
64 [Tip]Default 스크린세이버 가동 방법 2002.07.11 601
63 TCHAR, UNICODE, 그리고 윈도우 NT 2002.02.26 792
62 [C]밀리초를 구현하는 방법 2001.08.07 1275
61 [TIP]Convex Hull 알고리즘 2000.10.10 686
60 Lex와 Yacc의 사용법 강좌 2000.10.09 970
59 [C,ASM]어셈으로 윈도우메세지박스 띄우기 2000.08.16 774
58 [C소스]간단한 Hash 구현 2000.04.20 984
57 [C소스]사칙연산 파싱(Parsing) 2000.04.18 1431
56 [C소스]화일처리관련소스 2000.04.06 486
55 [구현]병렬처리기법의 개념 2000.03.11 1234
54 [ASM&C]Inline ASM- PC Speaker연주. 1999.12.13 600
53 [VC소스]Font정보를 이용한 텍스트핑퐁 1999.12.12 557
52 [ASM]PC-Speaker연주 1999.11.28 566
51 [ASM]4칙연산 계산기 소스 1999.11.22 1428