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
来写偏移量?