0
我試圖以編程方式編寫一些代碼來一個文件,然後進行編譯。我需要能夠在不替換整個文件的情況下添加代碼。我在文件末尾有一個}
,我需要刪除它才能添加下一批代碼,之後讀取}
。
我的代碼是目前這樣的:
//Writes from an offset from the end of a file.
static bool Write(const char *FilePath, const char *Text)
{
FILE *f;
errno_t error;
int seekerror;
if (!(error = fopen_s(&f, FilePath, "w")))
{
//one byte offset from the end of the file.
if (!(seekerror = fseek(f, -1, SEEK_END)))
{
fwrite(Text, sizeof(char), strlen(Text), f);
fclose(f);
return true;
}
}
return false;
}
問題
我相信w
和a
標誌從fseek()
重寫指針位置?所以我似乎無法覆蓋文件末尾的}
。
有沒有人知道我可以使用SEEK_END
來寫偏移量?