zoukankan      html  css  js  c++  java
  • strcmp 的实现方法

    #include <iostream>
    #include <string>
    using namespace std;

    int mystrcmp(const char * str1,const char * str2)
    {
            int i=0;
            while(1)
            {
                    if(str1[i]=='' &&str2[i]!='')
                    {
                            return -1;
                    }
                    else if(str1[i]!='' &&str2[i] == '')
                    {
                            return 1;
                    }
                    else if(str1[i]=='' &&str2[i] == '')
                    {
                            return 0;
                    }                
                    if(str1[i]<str2[i])
                    {
                            return -1;
                    }
                    else if(str1[i]>str2[i])
                    {
                            return 1;
                    }
                    i++;
            }
    }

    int main()
    {
            string str1;
            string str2;
            while(1)
            {
            getline(cin,str1);
            getline(cin,str2);
            cout<<"str1="<<str1<<endl;
            cout<<"str2="<<str2<<endl;
            cout<<mystrcmp(str1.c_str(),str2.c_str())<<endl;
        }
    }

  • 相关阅读:
    win2K/win2003终端服务器超出最大允许连接数解决之道
    DOM与SAX读取xml文件例程
    ubuntu安装配置telnet
    SCTP 简介
    groovy 脚本中文乱码问题解决
    编码问题研究
    gvim支持utf8
    ctags使用方法
    我家猫病了。。
    小朋友搞笑造句
  • 原文地址:https://www.cnblogs.com/wystan/p/4556368.html
Copyright © 2011-2022 走看看