1、追加内容信息
int WriteToStatistic(const char* buf,int len)
{
if (!len)
{
return -1;
}
FILE *fHandle = fopen("statistic/WMMPT.txt","a");
if (!fHandle)
{
return -1;
}
char* bufTemp = new char[len+2];
memset(bufTemp,0,len+2);
strncat(bufTemp,buf,len);
bufTemp[len] = '\n';
if ( len+1 != fwrite(bufTemp,1,len+1,fHandle) )
{
delete []bufTemp;
return -1;
}
fclose(fHandle);
delete []bufTemp;
return 0;
}
2、判断文件大小
int CheckWMMPTSize()
{
FILE* file = fopen("statistic/WMMPT.txt", "rb");
int size = 0;
if (file)
{
fseek(file, 0 ,SEEK_END);
size = ftell(file);
//当文件大于10M时自动删除文件
if(size > 10*1024*1024)
{
if( remove( "statistic/WMMPT.txt" ) == -1 )
printf( "Deleted statistic/WMMPT.txt\n" );
}
fclose(file);
}
return size;
}
3、写文件
void WriteToFlowMsg(UINT32 temp)
{
FILE *pFile=fopen("statistic/FlowMsg.txt","w");
char *pBuff = new char[12];
memset(pBuff,0,12);
sprintf(pBuff,"%d",temp+1);
fwrite(pBuff,1,strlen(pBuff),pFile);
fclose(pFile);
delete []pBuff;
}