Jump to content
  • Advertisement
Sign in to follow this  
adder_noir

An efficient way to find a string in a file!

This topic is 2610 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!