Originally Posted by
CommonTater
I don't think this is necessary --although it would be nice to have. I'd say just accept the question as given and get him started working on his code. Then if he runs into trouble, he can post up and ask specific questions.
One of the problems in a situation like this is "information overload" where basically we tell the poor guy too much and get him all confused.
Unless we are told other wise, I'd stay with my original recommendation... snag the whole file into memory and unleash strstr() on it.
Doesn't that method leave you open to false positives?
I mean if you read in to EOF, and the strings are:
Code:
IMG_12425
IMG_1423
IMG_1242
Which enter the buffer passed to fread like this:
Code:
IMG_12425\nIMG_1423\nIMG_1242
Then when you try to search for the last img (1242), by doing:
Code:
char *location = strstr(buffer, "IMG_1242")
And
Code:
if (location == buffer) // true
I mean I suppose you can always yank the string out up until the new line and then strcmp it with strlen to verify it that it's not larger...but I've seen substring methods yield false positives when one string happens to be a substring of another string (the requested string) within a given buffer.
Personally if I was going to cache it like that I'd use fread to capture it all, then use the string tokenizer to split it at new lines and toss them in a double pointer. While it's more computational at the beginning, I feel it will pay off.
Though that was kind of a segway. While it's not *necessary* anymore than anything else is, I believe it would help greatly to tell him what his next steps should be. Though I definitely hear where you're coming from in terms of information overload.