关天fseek(fp_Write, 0L, SEEK_END);指向文件未尾应用

lihualiu81 2009-04-29 04:18:13
关天fseek(fp_Write, 0L, SEEK_END);指向文件未尾应用
bool SaveToBookMark3(char* pBookMarkTitle, char* pUrl )
{
//char FullPath[256] = {"\\Windows\\收藏夹\\"};
char FullPath[256] = {"\\Windows\\Opera9\\Opera6.adr"};
//strcat((char*)FullPath , pBookMarkTitle);

char BookmarkPrex[32] = {"[InternetShortcut]"};

char CReturn[4] = {"\r\n"};
char CUrlHeader[8] = {"URL="};

FILE *fp_Write;
fp_Write =fopen(FullPath, "w+");
if (!fp_Write)
{
return false;
}

fseek(fp_Write, 0L, SEEK_END);
////line 1:
fwrite(BookmarkPrex, sizeof(char), strlen(BookmarkPrex), fp_Write);
fwrite(CReturn, sizeof(char), strlen(CReturn), fp_Write);

//line 2:
fwrite(CUrlHeader, sizeof(char), strlen(CUrlHeader), fp_Write);
fwrite(pUrl, sizeof(char), strlen(pUrl), fp_Write);

//line 3:
fwrite(CReturn, sizeof(char), strlen(CReturn), fp_Write);
fclose(fp_Write);

return true;
}

这样写为什么每次都把以前的内容覆盖了?fseek(fp_Write, 0L, SEEK_END);不能让指针指向文件未尾吗?
...全文
310 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
morris88 2009-04-29
  • 打赏
  • 举报
回复
该为:

FILE *fp_Write; 
fp_Write =fopen(FullPath, "a+");
if (!fp_Write)
{
return false;
}
happypay 2009-04-29
  • 打赏
  • 举报
回复
不知道你写完fwrite指针会不会移动要不你在每次fwrite之后再加一句fseek

19,506

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧