VS编写日志文件

来源:互联网 发布:大数据概念股龙头股票 编辑:程序博客网 时间:2024/05/24 04:28


/*日志定义*/

void logfile(char* sourceFile, int fileLine, char* str)

{

FILE *fp;                //#include <stdio.h>

SYSTEMTIME st;    //#include "winbase.h"

GetLocalTime(&st);

fp=fopen("test.log","a");

if(fp==0)

  {

return;

}

fprintf(fp, "%d-%d-%d %d:%d:%d (:%d):%s\r\n", st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond, fileLine, str);

fclose(fp);

}

/*引用*/

void flashfile(char* f,int sl,int el,uint16 cmd)
{
int RF,l;
long len;
volatile uint8 *rp;



RF=open(f,O_BINARY|O_RDWR);
if (RF==-1)
{
printf("open %s file error\n",f);
memset(temp, '\0', sizeof(temp));
sprintf("open %s file error",f);
logfile(__FILE__,__LINE__,temp);
exit(1);
}
if ((rp = (char*)malloc(0x10000)) == NULL)
{
printf("Not enough memory to allocate buffer\n");
logfile(__FILE__,__LINE__,"Not enough memory to allocate buffer");
exit(1);  
}

··········

}

原创粉丝点击