LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-04-2004, 08:46 PM   #1
saiz66
Member
 
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
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

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


Reply


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


All times are GMT -5. The time now is 02:43 PM.

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