Finding similar words from 2 strings
Hi all C++ gurus
help is desperately needed here...
basically i need to capture 2 user inputs
for example
sentence1: man
sentence2: this is a man
sentence 1 is part of sentence2
sentence1: boy
sentence2: this is a man
sentence 1 is not part of sentence 2
i need to use a while loop (end of sentence 2 or match found)
as well as a if loop to compare first char of sentence 1 to any match char in sentence 2
then use a while loop to test the rest of string 1 string2
i came up with the below code but somehow the loop doesn't work..it will always say sentence is not part of sentence 2 even though i type 2 same words
please help!! :( :(
================================================== ==========================================
Code:
#include <vcl.h>
#include "MT262io.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
AnsiString first;
AnsiString second;
bool flag = false;
int counter;
int count;
first = ReadStringPr("Enter 1st sentence: ");
second = ReadStringPr("Enter 2nd sentence: ");
int y = Length (first);
int x = Length(second);
while (count == x) //loop through 2nd string
{
if ( first[1] == second [counter]) //to check if first letter of first string matches any char in 2nd string
{
counter = counter +1;
while ( first[2] == second[counter] )
{
flag ==true;
WriteStringCr (" 1st sentence is part of 2nd sentence");
}
}
}
WriteStringCr("1st sentence is not part of second sentence" );
getchar();
return 0;
}