當(dāng)前位置:首頁 > 芯聞號(hào) > 充電吧
[導(dǎo)讀]使用環(huán)境:Windows 10,VS20151.一個(gè)例子:#include#include#include#define?MAXLEN?10 int?mon_log(char*?format,?..

使用環(huán)境:Windows 10,VS2015

1.一個(gè)例子:


#include#include#include#define?MAXLEN?10

int?mon_log(char*?format,?...)
{
	char?str_tmp[MAXLEN];
	int?i?=?0,?j?=?0;
	va_list?vArgList;
	va_start(vArgList,?format);
	i?=?vsnprintf(str_tmp,?MAXLEN,?format,?vArgList);
	va_end(vArgList);
	printf("%sn",?str_tmp);
	for?(j?=?0;?j?<?MAXLEN;?j++)
	{
	?????printf("%d??",?str_tmp[j]);
	}
	printf("n");
	return?i;
}

void?main()
{
	int?i?=?mon_log("%s,%d,%d,%c",?"abc",?2,?3,?'n');?
????????printf("%dn",?i);
	
	system("pause");
}

輸出:



vsnprintf會(huì)自動(dòng)在寫入字符的后面加上停止符