Suppose youre tasked with fixing a function definition that does not work as intended. The function is
Question:
Suppose you’re tasked with fixing a function definition that does not work as intended. The function is supposed to compare two strings and set the count to the number of identical characters, two characters are identical if they are the same character and are in the same position in the cstring. Note that cstrings are just character arrays that have ‘\0’ as their last character, for example
char name[7] = "harry";
might looks like this in memory:
h a r r y \0
The function usage is as follows:
compareCstrings(“SMC”, “SBCC”, count); // should set count to 1 compareCstrings(“basketball”, “Baseball”, count); // should set count to 2
Currently the function definition is:
void compareCstrings(const char *str1, const char *str2, int &count) { *count = 0; while (str1 != ‘\0’ || str2 != ‘\0’) { if( *str1 == *str2) *count++; str1++; str2++; } }
But this does not work, determine why not?