static void writeLog(const char *str) // 写字符串到文件,bLog表明是否为日志文件
{
FILE *fp = fopen("c:\\monitor.txt", "a+");
char curTime[100] = {0};
time_t t;
struct tm *tp;
t = time(NULL);
tp = localtime(&t);
int fmt = 1;
if(fmt == 0)
sprintf(curTime, "%2.2d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
else if(fmt == 1)
sprintf(curTime, "%2.2d-%2.2d-%2.2d", tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday);
else if(fmt == 2)
sprintf(curTime, "%2.2d:%2.2d:%2.2d", tp->tm_hour, tp->tm_min, tp->tm_sec);
int ret = fprintf(fp, "[%s] %s\n", curTime, str);
if(ret >= 0)
{
fflush(fp);
}
fclose(fp);
}
static void writeLogW(const WCHAR *str) // 写字符串到文件,bLog表明是否为日志文件
{
FILE *fp = fopen("c:\\monitor.txt", "a+");
WCHAR curTime[100] = {0};
time_t t;
struct tm *tp;
t = time(NULL);
tp = localtime(&t);
int fmt = 1;
if(fmt == 0)
swprintf(curTime, L"%2.2d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d", tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
else if(fmt == 1)
swprintf(curTime, L"%2.2d-%2.2d-%2.2d", tp->tm_year+1900, tp->tm_mon+1, tp->tm_mday);
else if(fmt == 2)
swprintf(curTime, L"%2.2d:%2.2d:%2.2d", tp->tm_hour, tp->tm_min, tp->tm_sec);
int ret = fwprintf(fp, L"[%s] %s\n", curTime, str);
if(ret >= 0)
{
fflush(fp);
}
fclose(fp);
}