void WritHexFile( char* szPath, char* pBuf, int nLen )
{
if (pBuf == NULL || nLen < 1)
{
return;
}
try
{
SYSTEMTIME systi;
GetLocalTime(&systi);
char szTime[128] = { 0 };
sprintf(szTime, "%04d/%02d/%02d %02d:%02d:%02d----", systi.wYear, systi.wMonth, systi.wDay, systi.wHour, systi.wMinute, systi.wSecond);
FILE* file;
file = fopen(szPath, "ab+");
fwrite(szTime, 1, strlen(szTime), file);
fwrite(pBuf, 1, nLen, file);
fwrite("\n", 1, 1, file);
fclose(file);
}
catch (exception* e)
{
printf("file error!\n",e);
}
}
void ReadHexFile(char* szPath, char* pBuf, int nLen)
{
if (pBuf == NULL || nLen < 1)
{
return;
}
try
{
FILE* file;
file = fopen(szPath, "ab+");
if (NULL == file)
{
printf("failed to open dos.txt\n");
return;
}
char szTest[1024] = { 0 };
while (!feof(file))
{
memset(szTest, 0, sizeof(szTest));
fgets(szTest, sizeof(szTest) - 1, file); // 包含了\n
printf("%s", szTest);
}
fclose(file);
}
catch (exception* e)
{
printf("file error!\n", e);
}
}