其他分享
首页 > 其他分享> > 串口日志保留进文件中

串口日志保留进文件中

作者:互联网

串口日志保留进文件中

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);
    }

}

标签:include,pFile,保留,char,串口,日志,NULL,strlen,acBuf
来源: https://www.cnblogs.com/xzpin/p/15831926.html