Searching/seeking in a text file

Started by
4 comments, last by Enokh 20 years, 6 months ago
Heya all. I'm working on a game where I've come the need to have the ability to search in a text file for a specific character, and then have the file pointer point to that character, like oh say the '[' one. I looked into seekg and had really weird results, any suggestions? Sorry if this question has been asked before, but the tutorials over at gametutorials.com didn't seem to have the right answer, and neither did a search over here on the forums. Thanks! [edited by - Enokh on October 10, 2003 8:52:02 PM]
Advertisement
file_pointer = fopen("file", "r");

while(fgetc(file_pointer) != ''['') ;
---------------------------------"Without C, all we would have is Pasal, Basi, and obol.""Black holes are where god divided by zero."http://www.insodus.com
Hmm say, wouldn't inputting word by word into strings and checking the first letter of the string be more efficient though than searching char by char?

[edited by - Enokh on October 11, 2003 7:52:14 AM]
quote:
Hmm say, wouldn''t inputting word by word into strings and checking the first letter of the string be more efficient though than searching char by char?
[/quote[
It would be less efficient because reading it in a word at a time is basically doing the same thing (reading in 1 char at a time), but it also has to check for whitespace and you have to store the string.

About the storing the string part, I''m working through fstream, so fgetc wouldn''t work, I''m just inputting into a char anyway with file_point << CharName.
while ((c = fstream.get()) != ''['')
{ }
Regards,Drew Vogel

This topic is closed to new replies.

Advertisement