Skip to main content
GameDev.net gamedev.net
🔒 Locked

An efficient way to find a string in a file!

Started by adder_noir Oct 23, 2011 at 2:10 AM 2 replies 1.4k views
Original Post
adder_noir
adder_noir
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
zacaj
zacaj
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
iMalc
iMalc
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)
adder_noir
adder_noir
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.