Hi,

Suppose I have a character array with the elements B,A,A. Now I have another character array with the elements A,B,B,B,A,A. How do I match the pattern B,A,A of the first character array with that of the second character array so as to produce the following output:
A B B B A A
- - - B A A
In other words, if a pattern is detected, the letters in a character array not matching any characters of the other array will have a dash underneath as shown.

I will really appreciate if somebody suggests some codes in C++.
Thanks

You could use strstr() to find the location of the pattern

Try using the find() from std::string.

Hi,

I am able to solve my problem using find() only if I know the length of the pattern. Is there a way to find the length of the pattern?

Any help much appreciated.

Thanks

If you have the pattern, how can you not know its length?

Suppose I have one character array as A,B,B,B,A,A,B and another character array as A,B,A,A,A. Now using find () I can find the second string matches the first where the pattern starts at B,A,A. Suppose I dont know the pattern. Using find() I can only find the match location but how do I find the length of the pattern? It may be mentioned that I take the two strings as input from the key board and for the given example, the output should be:

A B B B A A B
A - - B A A A


Any help much appreciated

Thanks

are you referring to the length of the string?

strlen