File_seek

Posted By: danohu

File_seek - 03/12/12 11:28

Hi

I want to search for multiple words in a .txt file:

file_seek(filehandle,0,0);
xndex = file_find (filehandle, "john");
xndexi = file_find (filehandle, "sam");

if...
if...
if...

When I run the code it will only look for the first name. How can I search for multiple criteria (i.e. multiple names at the same time).

I have been trying options without much success e.g.

xndex = file_find (filehandle, "john"; "sam");

Would anyone be able to point me in the right direction please?

I could search for a single word followed by if statements but without searching for multiple criteria at the same time (i.e. different names) the code is inefficient and very long.

Thanks for your help in advance!

D
Posted By: Widi

Re: File_seek - 03/12/12 13:46

try this:

file_seek(filehandle,0,0);
xndex = file_find (filehandle, "john");
file_seek(filehandle,0,0); // set the reader back to the beginning of the file
xndexi = file_find (filehandle, "sam");
Posted By: danohu

Re: File_seek - 11/03/13 17:58

I have a follow-up question having come back to this after some time. If one has a single word for xndex i.e. "john" and a single word for xndexi "sam", then if one is searching for lots of names one will have a lot of xndexs and a lot of code i.e.

if (xndex > 0 && xndexi > 0 && xndexii > 0 etc etc)

I wondered if anyone could help me explain the following?

I have written:

file_seek(filehandle,0,0);
xndex = file_find (filehandle, "john") && file_find (filehandle, "sam");

if (xndex > 0)
..then xyz

The code runs without an error appearing and is less involved. However, if on searches for the two words in a word document (coding for finding the words in a word document has not been included but is in my script)
the code says xndex is greater than 0 if the two words are found as well as if they are not. Clearly the code is not working.

My question is... I wonder if there is a way to make xndex represent more than one word?

Many thanks for your help.
© 2024 lite-C Forums