1.判断二个字符串是否相等,可以模仿strcmp.当二个字符串相等的时候ruturn 0.,当二个字符串小于时返回为小于0,当二个字符串大于时返回为大于0。const为不可以更改。
//方法一
int my_strcmp(const char* arr1, const char* arr2)
{assert(arr1 &&arr2);while (*arr1==*arr2){if (*arr1 == '\0'){return 0;}*arr1 ++ ;*arr2++;}return (*arr1 - *arr2);
}
int main()
{char arr1[20] = { "zhangsan" };char arr2[20] = { "zhangsana" };int ret=my_strcmp(arr1, arr2);if (ret == 0)printf("==\n");if (ret<0){printf("<\n");}if (ret > 0){printf(">\n");}return 0;}