串口日志保留进文件中
串口日志保留进文件中
sample:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv)
{
static FILE *pFile = NULL;
char *acBuf = "ctest some code";
printf("strlen = %d acBuf = %s\n", strlen(acBuf), acBuf);
if (pFile == NULL) {
pFile = fopen("/tmp/x.txt", "wb");
}
if (pFile != NULL) {
fwrite(acBuf, sizeof(char), strlen(acBuf), pFile);
fwrite("\n", 1, 1, pFile);
fflush(pFile);
}
}