/*---------------------------------------------------------------------------
File name: bccn-使用fwrite遇到的问题.c
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 10/18/2007 09:28:24
Environment: WinXPSP2 En Pro + VS2005 v8.0.50727.762
Modification history:
===========================================================================
Problem statement:
---------------------------------------------------------------------------
http://bbs.bc-cn.net/viewthread.php?tid=178760
[求助]使用fwrite遇到的问题
如题,第一次写了一批数据到一个文件中,然后关闭该文件;再打开该文件,接着上次写的末尾(或者在另外的某个位置),再写数据进去,该如何操作.先谢谢各位咯!
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp;
int i;
char filename[] = "a.txt";
fp = fopen(filename, "w");
fwrite("abcd", 4, 1, fp); //abcd
fclose(fp);
fp=fopen(filename, "a");
fwrite("efg", 3, 1, fp); //abcdefg
fclose(fp);
fp=fopen(filename, "r+");
fseek(fp, 1, SEEK_SET);
fwrite("hi", 2, 1, fp); //ahidefg
fclose(fp);
return 0;
}