如何打印调试字符串?

#include <Windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <stdio.h>
#include <wchar.h>
static void dbg(const char *fmt, ...)
{
	//获取时间并减去 8 小时时差
	struct timespec ts;
	timespec_get(&ts, TIME_UTC);
	ts.tv_sec += 28800;

	//格式化时间
	char time_buf[32];
	size_t rc = strftime(time_buf, sizeof time_buf, "[%Y-%m-%d %T", gmtime(&ts.tv_sec));
	int time_lenght = snprintf(time_buf + rc, sizeof time_buf - rc, ".%06ld UTC+8]", ts.tv_nsec / 1000);

	//获取参数列表
	va_list args;
	va_start(args, fmt);

	//打印参数列表
	char message[9216] = { 0 };
	vsnprintf_s(message, 9216, 9216 - 1, fmt, args);

	//组合格式化的时间和参数列表字符串
	char debug[10240] = { 0 };
	sprintf_s(debug, 10240, "%s [debug] %s", time_buf, message);

#ifdef WINBASEAPI
	OutputDebugStringA(debug);
#else
	printf("%s\n", debug);
#endif
}
posted @ 2018-05-26 13:32  學海無涯  阅读(523)  评论(0编辑  收藏  举报