Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 26-03-2008, 10:08 AM   #1 (permalink)
I don't want IT
 
DizitalNovice's Avatar
 
Join Date: Jul 2006
Location: BLR (hell part 2)
Posts: 48
Question Word search program in C


I want to make a program in C which will take a string input and replace predefined words(available in a text file) with *s. Can be used to replace offensive words in a file,etc. But I don't get the word searching algo. ie After I read a word from the input, how do I search whether that word is in the given list or not? Please help!
DizitalNovice is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 26-03-2008, 12:17 PM   #2 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Word search program in C

Quote:
Originally Posted by DizitalNovice View Post
I want to make a program in C which will take a string input and replace predefined words(available in a text file) with *s. Can be used to replace offensive words in a file,etc. But I don't get the word searching algo. ie After I read a word from the input, how do I search whether that word is in the given list or not? Please help!
See this source code - ftp://tron.um.u-tokyo.ac.jp/pub/GNU/grep/ or http://www.opensource.apple.com/darw...p-14/grep/src/
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 26-03-2008, 05:20 PM   #3 (permalink)
I don't want IT
 
DizitalNovice's Avatar
 
Join Date: Jul 2006
Location: BLR (hell part 2)
Posts: 48
Default Re: Word search program in C

I cud not understand a thing in the links. Can someone offer something simpler.I'm looking for a simple short program. Can't write 10 files for this stuff!
DizitalNovice is offline  
Old 26-03-2008, 05:23 PM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Word search program in C

An algorithm for searching the file you mention having the list line by line:

Code:
While file-pointer != EOF
    While readchar() != '\n' // New line char
        Keep reading char
    //Now if \n is encountered
    Check if word input == readchar() array so far and perform necessary action
    // Clear readchar() array
Loop
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 27-03-2008, 12:09 PM   #5 (permalink)
I don't want IT
 
DizitalNovice's Avatar
 
Join Date: Jul 2006
Location: BLR (hell part 2)
Posts: 48
Exclamation Re: Word search program in C

@qwertymaniac
Thanks for your help! I still have a doubt. Your program will check for a word input by the user to match words in a file , but what I want is that the list of words to be checked exists in a file (say offensive_words.txt) and the user inputs a string. Then we check the words in the user's string one by one to check whether any word in the offensive_words.txt file is present there.If it is then we replace the whole word with *s. and then print the modified String.
DizitalNovice is offline  
Old 27-03-2008, 04:36 PM   #6 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Word search program in C

Um why don't you look at string.h's functions for a change? Its got all those find(), strcmp() functions in it which would be exactly what you require.

And as for breaking the input into words, make a temp variable store characters only until a space is encountered and do the operation on that and then in the next iteration clear that temp and loop.

You can also store the file contents temporarily post reading into a Linked-List or a string array.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 27-03-2008, 06:09 PM   #7 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Word search program in C

why not to use strstr() to check for substring ?
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make pdf / word book..from isolated pdf/word pages ? mkmkmk Software Q&A 11 13-07-2009 12:09 PM
Search Goes Open Source: Wikia Search Rahim Open Source 3 14-02-2008 08:56 PM
Add Site Search To Firefox Search Bar IN JUST ONE MINUTE! dfordigit Tutorials 7 23-03-2007 12:20 PM
new program in 'close program menu' list and more....... vishakadatta QnA (read only) 2 12-04-2005 11:33 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2