LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   [c] searching for a word in a file (http://www.linuxquestions.org/questions/programming-9/%5Bc%5D-searching-for-a-word-in-a-file-238850/)

saiz66 10-04-2004 08:46 PM

[c] searching for a word in a file
 
How do I search a file for a specified keyword? I just dont really know how to traverse through a file with all the spaces and tabs and new lines... Thanks a lot!!!

aluser 10-04-2004 09:46 PM

The function you probably want is strstr() from <string.h>. You could use getline() or fgets() to iterate through the file line-by-line.

If it's not acceptable to find "foobar" when searching for "foo", you'll need some logic to avoid that.

I'm being a little vague because this sounds like homework :D


All times are GMT -5. The time now is 10:15 AM.