你怎么写在C一个txt文件的指定行? [英] How do you write to a specific line of a txt file in C?

查看:121
本文介绍了你怎么写在C一个txt文件的指定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖一定行的一个txt文件,同时保持所有其他一样。是否有这样做的一个很好的和简单的方式?

I would like to overwrite a certain line in a txt file while keeping all others the same. Is there a nice and simple way of doing this?

推荐答案

Basicly使用FSEEK()来搜索你想改变比特序列,结果
然后使用FWRITE()来覆盖旧文本搜索

Basicly use Fseek() to search the sequence of bits that you want to change,
then use Fwrite() to overwrite the old text

OBS:你需要在RW模式下打开的文件覆盖结果

OBS: you need to open the file in rw mode to overwrite

fopen ("myfile.txt", "wr");

使用这些referenses:

use those referenses:

http://www.cplusplus.com/reference/cstdio/fwrite/结果
http://www.cplusplus.com/reference/cstdio/fseek/

(它说,C ++,但工作在C)

(it says C++ but works on C)

这篇关于你怎么写在C一个txt文件的指定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆