Hey I am trying to write a function that returns true if two c strings are the same, but it keeps returning false.
1 2 3 4 5 6 7 8 9 10 11 12
bool strequal(constchar str1[], constchar str2[])
{
while (str1 != 0 && str2 != 0)
{
if (*str1 != *str2) // compare corresponding characters
returnfalse;
str1++;
str2++; // advance to the next character
}
return (str1 == str2); // both ended at same time
}
I changed the while loop to while (*str1 != '\0' && *str2 != '\0') and bool strequal(constchar* str1, constchar* str2)
But its still false. I dont think the loop is working right