// console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <STDARG.H>
using namespace std;
enum enumTest
{
one = 1,
two,
three,
four
};
double 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 * 1.0 / count) : 0 );
}
int printm(const TCHAR *first, ...)
{
TCHAR arr[100];
memset(arr, NULL, sizeof(arr) / sizeof(TCHAR));
va_list paraList = NULL;
const TCHAR *pNextParam = NULL;
va_start(paraList, first);
pNextParam = first;
int count = 0;
do
{
if (pNextParam)
{
swprintf_s(arr + count, sizeof(arr) / sizeof(TCHAR) - count, _T(" %s"), pNextParam);
count += wcslen(pNextParam) + 1;//1 is a space from “ %s"
}
pNextParam = va_arg(paraList, TCHAR*);
}while(pNextParam);
wprintf(_T("%s"), arr);
return wcslen(arr) > 0 ? 1 : 0;
}
int main()
{
double x = average(1, 2, 3, 5, 8, -1);
cout << x << endl;
printm(_T("12"), _T("34d"), _T("fdgdfg"), _T("fdgj"));
system("pause");
return 0;
}
//
#include "stdafx.h"
#include <iostream>
#include <STDARG.H>
using namespace std;
enum enumTest
{
one = 1,
two,
three,
four
};
double 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 * 1.0 / count) : 0 );
}
int printm(const TCHAR *first, ...)
{
TCHAR arr[100];
memset(arr, NULL, sizeof(arr) / sizeof(TCHAR));
va_list paraList = NULL;
const TCHAR *pNextParam = NULL;
va_start(paraList, first);
pNextParam = first;
int count = 0;
do
{
if (pNextParam)
{
swprintf_s(arr + count, sizeof(arr) / sizeof(TCHAR) - count, _T(" %s"), pNextParam);
count += wcslen(pNextParam) + 1;//1 is a space from “ %s"
}
pNextParam = va_arg(paraList, TCHAR*);
}while(pNextParam);
wprintf(_T("%s"), arr);
return wcslen(arr) > 0 ? 1 : 0;
}
int main()
{
double x = average(1, 2, 3, 5, 8, -1);
cout << x << endl;
printm(_T("12"), _T("34d"), _T("fdgdfg"), _T("fdgj"));
system("pause");
return 0;
}