util.c

来自「其他 其他 其他 其他 其他 其他 其他 其他 其他 其他」· C语言 代码 · 共 52 行

C
52
字号
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "util.h"#define  LOG_PATH   "./log/"/*写运行日志*/void WriteLog(char *s){  char  filename[64];  FILE  *fp = NULL;  time_t  clock;  struct tm  *timep = NULL;  memset(filename,0x00,sizeof(filename));  	  if(s == NULL)	return;  clock = time(NULL);  timep = (struct tm *)localtime(&clock);  sprintf(filename,"%s%04d%02d%02d.log",LOG_PATH,timep->tm_year+1900,timep->tm_mon+1,timep->tm_mday);  fp = fopen(filename,"a");  fprintf(fp,"[%04d/%02d/%02d %02d:%02d:%02d]%s\n",	timep->tm_year+1900,      timep->tm_mon+1,timep->tm_mday,      timep->tm_hour,timep->tm_min,      timep->tm_sec,s);  fflush(fp);  fclose(fp);    return ;}/*去字符串空格*/void  PackString(char *str){  char  *pcS = str;  char  *pcD = str;    while(*pcS)  {	if( *pcS != ' ')	*pcD++ = *pcS;	pcS++;  }  *pcD = 0;    return;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?