This C++ assignment asks to write a function that determines ifa C-string begins with a specified prefix. It should have thefollowing signature:
bool starts(char *str, char *prefix)
It should return true if str begins withprefix, false if not. It should return false ifprefix is longer than str. Seethe table below for some examples of what your function shouldreturn for various cases:
str | prefix | returns |
airplanes | air | true |
airplanes | abc | false |
airplanes | plane | false |
airplanes | airplane | true |
air | airplane | false |
Assume that the pointers passed to it are pointers to valid,null-terminated C-Strings. If you wish, you can use the strlen()and strcmp() functions, but it isn't required.
Hint: it can make things easier to check if length ofprefix > length of str. If so,you can immediately return false! If not, you can continue on withyour check.