在C中的文本文件中搜索字符串 [英] search a string in text file in C

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

问题描述

大家好,

i必须使用C程序搜索txt文件中的一个单词,我试过但输出没有正确...请给我一个流程...



i是C的新手...



问候....

srini

hi everyone,
i have to search a one word in txt file using C program,..I tried but output not comming right...please give me a flow for that...


i am newbie to C...


regards....

srini

推荐答案


大家好,

i必须搜索一个在使用C程序的txt文件中的一个单词,..我试过但输出没有正确...请给我一个流程...



i am newbie to C ...


问候....


srini
hi everyone,
i have to search a one word in txt file using C program,..I tried but output not comming right...please give me a flow for that...


i am newbie to C...


regards....

srini



让我们看看你写的代码。

Let''s see the code you''ve written.



让我们看看你的代码写了。
Let''s see the code you''ve written.



i已将所有数据读入一个缓冲区....从中我必须搜索单词...


看看我的代码....

i have read all datas into one buffer....from that I have to search the word...

see my code....

展开 | 选择 | Wrap | 行号


嗨Srini,


从代码中我看到ftell(pFile)将指向文件的开头,因此它的输出为0.这是因为你在fseek func中使用了SEEK_SET,它将带你到文件的开头。尝试在代码中将fEek调用中的SEEK_SET更改为SEEK_END,将光标移动到文件末尾。现在ftell(pfile)将为您提供将打印输出的光标值。


希望以下代码适合您。

Hi Srini,

From the code I see that ftell(pFile) will point to the beginning of the file and hence its ouput is 0. This is because you have used SEEK_SET in the fseek func which will bring you to the begining of the file. Try changing SEEK_SET to SEEK_END in the fseek call in the code which moves the cursor to the end of your file. now ftell(pfile) will give you the cursor value which will print the output.

Hope the following code works for you.

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号


这篇关于在C中的文本文件中搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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