An efficient way to find a string in a file!

Started by
2 comments, last by adder_noir 12 years, 6 months ago
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 :)
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
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
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.

This topic is closed to new replies.

Advertisement