C语言:strcmp函数的实现

#define _CRT_SECURE_NO_WARNINGS//strncmp
#include
#include
#include
#include

int my_strcmp(const char *dest, const char *str)
{
 assert(dest != NULL&str != NULL);
 const char* d = dest;
 const char* s = str;

 
 
 while ((*dest == *str)&&*dest!='\0')
 {
  dest++;
  str++;
 }
  if( *dest < *str)
  {
   return -1;
  }
  else if (*dest>*str)
  {
   return 1;
  }
  return 0;
}
int main()
{
 char arr1[20] = "abc";
 char arr2[20] = "abcd";

 printf("%d", my_strcmp(arr1, arr2));

 system("pause");
 return 0;
}

你可能感兴趣的:(代码)