1. 程式人生 > >軟體素材---linux C語言:向檔案末尾進行追加資料

軟體素材---linux C語言:向檔案末尾進行追加資料

void AppendDataToFile(char* filePath, char* msg)
{
  

    // 以附加方式開啟可讀/寫的檔案, 如果沒有此檔案則會進行建立,然後以附加方式開啟可讀/寫的檔案
    FILE* fp = fopen(filePath, "a+");
    if (fp==0)
    {
        printf("can't open log file\n");
        return;
    }
    fseek(fp, 0, SEEK_END);//定位到檔案末尾
    fwrite(msg, strlen(msg), 1, fp);//講msg對應的字串append到檔案末尾
    fclose(fp);

   
}

 

Ref:

https://blog.csdn.net/qq_31243065/article/details/82354557

https://zhidao.baidu.com/question/83212659.html