;***
;strcmp - compare two strings, returning less than, equal to, or greater than
;
;Purpose:
;       Compares two string, determining their lexical order.  Unsigned
;       comparison is used.
;
;       Algorithm:
;          int strcmp ( src , dst )
;                  unsigned char *src;
;                  unsigned char *dst;
;          {
;                  int ret = 0 ;
;
;                  while( ! (ret = *src - *dst) && *dst)
;                          ++src, ++dst;
;
;                  if ( ret < 0 )
;                          ret = -1 ;
;                  else if ( ret > 0 )
;                          ret = 1 ;
;
;                  return( ret );
;          }
;
;Entry:
;       const char * src - string for left-hand side of comparison
;       const char * dst - string for right-hand side of comparison
;
;Exit:
;       AX < 0, 0, or >0, indicating whether the first string is
;       Less than, Equal to, or Greater than the second string.
;
;Uses:
;       CX, DX
;
;Exceptions:
;
;*******************************************************************************

 
 
 
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>

char *mystrcmp(char *src, const char *dst)
{
	int ret = 0;

	while (!(ret = *src - *dst) && *dst)
		++src, ++dst;

	if (ret < 0)
		ret = -1;
	else if (ret > 0)
		ret = 1;

	return (ret);
}

int main(int argc, char* argv[])
{
	char dst[] = "dest";
	char *src = "desr";

	printf("%d", mystrcmp(dst, src));
	return 0;
}

相关文章:

  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-01-22
  • 2022-12-23
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2021-11-26
  • 2022-01-14
  • 2021-08-18
  • 2022-01-17
  • 2022-02-25
相关资源
相似解决方案