Question: In C++ write a function that recursively checks if two C-strings match, in other words have the same contents up to the length of the
In C++ write a function that recursively checks if two C-strings match, in other words have the same contents up to the length of the shorter string . If both strings match the function returns true and otherwise returns false . For example if s is "abc" and t is "abc" or "abcd" then match(s,t) returns true . On the other hand, if s is "abce" and t is "abcd" then match(s,t) returns false . Unlike the equal function you wrote earlier, we will consider two s and t to match even if the lengths are different, as long as they match up to the last character of the shorter string . In particular, the empty string matches any other string . Your base cases will be when one of the two strings is empty (return true ) or if both strings are nonempty and start different characters (return false ). The recursive call will be on s+1 and t+1. NOTE: a C-string s is empty if s[0] == '\0'.
Prototype: bool match(const char *s, const char *t);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
