GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Apr-2008, 12:02
zr3cool zr3cool is offline
New Member
 
Join Date: Apr 2008
Posts: 3
zr3cool is on a distinguished road
Smile

Locate similar words/phrases that are common to both files


heres the program description....

There exist two test files that are not identical with a size of between 100 and 250 characters. Write a c++ program that will read in these two text files, prompt the user for a length factor some value between 5 and 20 and locate similar (words phrases) that are common to both files. print the results of both files and similar words between them.

HELP ME PLEASE...
i know how to read from a text file but i dont know how to compare it..
thanks.
  #2  
Old 01-Apr-2008, 12:49
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough

Re: c++ program..i need help please....


Are the input files formatted in any certain way or is it just random words. That will make a difference. If they are just random words that you have to compare, then the only way I can think to do it is a brute force approach:

1) Read the first word from one file into a string
2) Read the first word of the second file into a string
3) Compare the two strings
4) Read the next word of the second file into the string 2
5) Repeat steps 3 and 4 until you reach the end of the file
6) Get the next word of the first file
7) Repeat steps 2 - 6 until you reach the end of the first file.
8) Print your results.

If you have to compare file 1 word1 to file 2 word1, and then file1 word2 to file2 word2, etc. That is a simple read, compare, print.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
  #3  
Old 01-Apr-2008, 13:04
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: c++ program..i need help please....


From the description, it sounds more like the files are just a bunch of characters, not necessarily formatted in any way. Maybe something like:

Code:
abcdefghallajjekkejjimmycrackcorn and I don't care, yadda yadda yadda asd;fl asdlkjlkjeejejkjjfllgidforums.com is the place to beif you like good postings.
Then, you'd enter a number (5 for instance) and it would compare each seqeunce of 5 characters from file one until it found a match of the sequence for all 5-character sequences from file 2. So, in this example, you would start with the sequence "abcde", and search file 2 for that sequence, then you would go the next sequence "bcdef", etc.
  #4  
Old 02-Apr-2008, 08:28
zr3cool zr3cool is offline
New Member
 
Join Date: Apr 2008
Posts: 3
zr3cool is on a distinguished road

Re: c++ program..i need help please....


its exactly what fakepoo said...
  #5  
Old 02-Apr-2008, 09:06
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Locate similar words/phrases that are common to both files


CPP / C++ / C Code:
string file1;
// TODO: Load the first file into file1

string file2;
// TODO: Load the second file into file2

int lengthFactor;
// TODO: Get the length factor from the user

for(i=0;i<file1.length();++i)
{ if( file2.find( file1.substr( i, lengthFactor) ) != npos )
  { // file1.substr(i,lengthFactor) was found in file2 so do whatever you want with it
  }
}//end for(i)
  #6  
Old 05-Apr-2008, 12:47
zr3cool zr3cool is offline
New Member
 
Join Date: Apr 2008
Posts: 3
zr3cool is on a distinguished road

Re: Locate similar words/phrases that are common to both files


thanks a lot ..thats good start
ok ill try to put it together and maybe you can help me finalize it.. thx
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
Pipeline freeze simulation darklightred CPP / C++ Forum 6 27-Jul-2006 19:37
Help with a complex program lordfuoco CPP / C++ Forum 5 24-Jun-2006 06:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:02.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.