Jump to content

  • Log In with Google      Sign In   
  • Create Account

An efficient way to find a string in a file!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 adder_noir   Members   -  Reputation: 271

Like
0Likes
Like

Posted 22 October 2011 - 08:10 PM

Hi, is there a way to find a specific char string in a file using the fread and all those f functions without going into large comparison iteration loops?

I've looked through all these f functions that I know of and I can't find anything? Any ideas? Cheers :)

Sponsor:

#2 zacaj   Members   -  Reputation: 643

Like
1Likes
Like

Posted 22 October 2011 - 08:26 PM

There's no specific functions for that, the f* functions don't deal with what's in the files, just read the data in. There is a str* function that searches for one string in another, you could read in the whole file and then use that, but tge file couldn't be very big for that to be practical

#3 iMalc   Crossbones+   -  Reputation: 2306

Like
1Likes
Like

Posted 22 October 2011 - 09:42 PM

There are various algorithms, like Boyer-Moore, but really if it's on disk then your bottleneck is most likely disk IO.
I'd most certainly just start off with the basic obvious solution. Those other algorithms are all targeted at very specific situations. We'd need to more about the string you're searching for etc:
String length
File length
Number of distinct characters in the string
Number of distinct characters in the file (if known)
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

#4 adder_noir   Members   -  Reputation: 271

Like
0Likes
Like

Posted 24 October 2011 - 07:40 PM

Ok thanks for the information. I voted you guys all up :)

I've found a way if anyone is interested? It uses some standard functions and a small one I wrote too.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS