Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-04-2004, 08:46 PM   #1
Registered: Apr 2003
Posts: 225

Rep: Reputation: 30
[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!!!

Last edited by saiz66; 10-04-2004 at 08:51 PM.
Old 10-04-2004, 09:46 PM   #2
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
searching a file in my hardisk... itz2000 Linux - Newbie 1 10-31-2005 12:45 PM
File Searching gfrair Linux - Newbie 1 03-14-2005 06:24 PM
Searching patterns from file MichaelVaughn Programming 1 04-06-2004 11:18 AM
File Searching JC404 Linux - Newbie 2 08-02-2003 08:45 PM
searching through a file albean Linux - Newbie 8 11-23-2002 08:16 PM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration