不使用库函数,编写函数int strcmp(char *source, char *dest) 相等返回0,不等返回-1

#include 

int strcmp(char *source, char *dest)
{
while(*source == *dest && *source != '\0' && *dest != '\0')
{
   source++;
   dest++;
}
if (*source =='\0' && *dest == '\0')
  return 0;
else
  return -1;


}
int main()
{
char *str1 = "abcde";
char *str2 = "abcde";
printf("ret = %d", mystrcmp(str1, str2));

return 0;
}


你可能感兴趣的:(c/c++)