C编辑文件 [英] C editing a file

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

问题描述

大家好。

我要编辑一个txt文件,删除一个给定的单词。


我的方法是打开文件并阅读它由char填充,将其复制到第二个文件。

我使用缓冲区来识别给定的单词,所以如果我识别出模式,我就不会将它传递给新文件。最后,我将新文件复制到前者。


有没有更好的方法来执行我的任务,也许可以编辑in loco。 (不使用支持文件)?

在打开文件之前,我知道该单词所在的行/行。

例如:cat,row 3,row 5两次,第13行。加速过程是否有用?

Hi all.
I''ve to edit a txt file, deleting a given word.

My approach is to open the file and read it char by char, copying that to a second file.
I use a buffer to identify the given word, so if I recognize the pattern I don''t pass it to the new file. Finally I copy the new file to the former.

Is there a better way to carry out my task, maybe editing "in loco" (without using a support file)?
Before opening the file I know in which row/rows the word is located.
For example: cat, row 3, row 5 twice, row 13. Is it someway useful to speed up the process?

推荐答案


大家好。

我必须编辑一个txt文件,删除给定的单词。


我的方法是打开文件并通过char读取它,将其复制到一个第二个文件。

我使用缓冲区来识别给定的单词,所以如果我识别出模式,我就不会将它传递给新文件。最后,我将新文件复制到前者。


有没有更好的方法来执行我的任务,也许可以编辑in loco。 (不使用支持文件)?

在打开文件之前,我知道该单词所在的行/行。

例如:cat,row 3,row 5两次,第13行。加速这个过程是否有用?
Hi all.
I''ve to edit a txt file, deleting a given word.

My approach is to open the file and read it char by char, copying that to a second file.
I use a buffer to identify the given word, so if I recognize the pattern I don''t pass it to the new file. Finally I copy the new file to the former.

Is there a better way to carry out my task, maybe editing "in loco" (without using a support file)?
Before opening the file I know in which row/rows the word is located.
For example: cat, row 3, row 5 twice, row 13. Is it someway useful to speed up the process?



如果您有行/列,则可以快速定位单词。


如果你对这个词一无所知(假设你必须维护订单或文件),我会搜索文件。如果你担心效率,也许你可以逐字逐句,而不是整个字符串竞争。


如果文件有一些顺序,你可以制作一个切割器算法。例如,如果您的文件已排序,您可以执行不同的搜索以提高效率。

If you have the row/column, you can target the word quickly.

if you know nothing about the word, (assuming you must maintain order or the file), I would search the file. If you are worried about efficiency, maybe you can compair letter by letter instead of whole string compairs.

If there is some order to the file, you can possibly make a cleaver algorithm. For example, if your file is sorted, you can perform different searches to enhance efficiency.



如果您有行/列,可以快速定位这个词。


如果你对这个词一无所知(假设你必须维护订单或文件),我会搜索文件。如果你担心效率,也许你可以逐字逐句,而不是整个字符串竞争。


如果文件有一些顺序,你可以制作一个切割器算法。例如,如果您的文件已排序,则可以执行不同的搜索以提高效率。
If you have the row/column, you can target the word quickly.

if you know nothing about the word, (assuming you must maintain order or the file), I would search the file. If you are worried about efficiency, maybe you can compair letter by letter instead of whole string compairs.

If there is some order to the file, you can possibly make a cleaver algorithm. For example, if your file is sorted, you can perform different searches to enhance efficiency.



您好,感谢您的回复。

我的文件没有排序,它是一个随机的txt文件,例如程序自述文件.txt或论坛FAQ,所以单词可以按任何顺序发生。

我知道单词出现的行/行,如果有的话,但我不是专栏。

如上例所示我知道:


字:cat,row 3,row 5两次,row8。

字:dog,不存在。


我正在寻找一个好的效率!

Hello, thanks for the reply.
My file is not sorted, it''s a random txt file, for example a program readme.txt or a forum FAQ, so words can occur in any order.
I know the row/rows in which the word occurs, if any, but I haven''t the column.
As in the example above I know:

word: cat, row 3, row 5 twice, row8.
word: dog, not present.

I''m in search for a good efficiency!



你好,谢谢你的回复。

我的文件没有排序,它是一个随机的txt文件,例如程序readme.txt或论坛FAQ,所以单词可以按任何顺序出现。 />
我知道单词出现的行/行,如果有的话,但我不是专栏。

如上例所示,我知道:


字:猫,第3行,第5行两次,第8行。

字:狗,不存在。


我'我在se拱门效率很高!
Hello, thanks for the reply.
My file is not sorted, it''s a random txt file, for example a program readme.txt or a forum FAQ, so words can occur in any order.
I know the row/rows in which the word occurs, if any, but I haven''t the column.
As in the example above I know:

word: cat, row 3, row 5 twice, row8.
word: dog, not present.

I''m in search for a good efficiency!



我真的不知道你做了什么或你有什么限制,所以我的想法是无限的。


而不是逐字解析文件,我建议使用strstr函数指向该字符串的每个实例。
strstr


这篇关于C编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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