zoukankan      html  css  js  c++  java
  • strcmp实现

    ;***
    ;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;
    }
    
  • 相关阅读:
    OC
    OC
    OC
    OC
    OC
    Oracle wm_concat()函数
    字符串拼接
    easyui扩展数据表格点击加号拓展
    子tab里面新增tab(top.jQuery)
    combox datagrid重复请求问题
  • 原文地址:https://www.cnblogs.com/helloweworld/p/2803854.html
Copyright © 2011-2022 走看看