在C最后一行前项附加到文件 [英] Append item to a file before last line in c

查看:93
本文介绍了在C最后一行前项附加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页脚应与当前的时间和小时更新,当一个新项目添加到该文件。
下面是示例文件格式,

The footer should update with current time and hour when a new Item added to the file. Here is the sample file format,

ITEM1结果
ITEM2结果
06/07/2010十点20分22秒 //页脚行

ITEM1
ITEM2
06/07/2010 10:20:22 //footer line

的项目具有现有文件中追加,页脚行之前和页脚应该用新值来更新。
我有变量,项和时间,它持有的相应值的字符串。

The "item" has to append in the existing file, prior to the footer line, and the footer should be updated with new value. I am having to variables, "item" and "time" which hold the respective values as string.

添加一个新的项目(ITEM3)的文件看起来像后,

After adding a new item (ITEM3) the file looks like,

ITEM1结果
ITEM2结果
ITEM3结果
07/07/2010 17时20分十二秒 //改变页脚

ITEM1
ITEM2
ITEM3
07/07/2010 17:20:12 //changed footer

帮我达致这。

推荐答案

由于页脚行是静态长度...

Since the footer line is a static length...

寻求到页脚行的开头,写上新的项目在它跟着一个新行,然后写出来的新注脚。

Seek to the beginning of the footer line, write the new item over it followed by a newline, then write out the new footer.

(注意,此过程是危险的,如果你不能保证,你将永远写至少足够的总字节覆盖现有的页脚,但它看起来像你正是保证这里。)

(Note that this procedure is dangerous if you can't guarantee that you will always write at least enough total bytes to overwrite the existing footer, but it looks like you have exactly that assurance here.)

这篇关于在C最后一行前项附加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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