- 论坛徽章:
- 0
|
一直觉得C不能直接对磁盘文件操作, 而是把文件全部读到内存理, 操作完成后,
在全部写回磁盘。 可是下面这个程序确实可以工作, 不知道哪位高手知道
其内部的实现思路大概是怎么的?
个人觉得应该是: 读到内存-改-写回内存
bash-3.1$ cat test.txt
This is a test file
for test04.c. |
执行下面程序:
#include <stdio.h>
int main(void)
{
char *fname = "test.txt";
FILE *fp;
fp = fopen(fname, "r+");
fseek(fp, 0, SEEK_END);
fprintf(fp, "hello, world!\n");
return 0;
} |
结果:
bash-3.1$ cat test.txt
This is a test file
for test04.c.
hello, world! |
|
|