so true

          心懷未來,開創未來!
          隨筆 - 160, 文章 - 0, 評論 - 40, 引用 - 0
          數據加載中……

          我給出的strcmp源碼

          源碼:

          int strcmp(const char * str1, const char *str2){
           do{
            if(!str1 || !*str1)return (!str2 || !*str2) ? 0 : -1;
            if(!str2 || !*str2)return 1;
           }while(*str1++==*str2++);
           return *(str1-1)-*(str2-1);
          }

          測試:

           cout<<strcmp(NULL,NULL)<<endl;
           cout<<strcmp("abc",NULL)<<endl;
           cout<<strcmp(NULL,"abc")<<endl;
           
           cout<<strcmp("abc","abc")<<endl;
           cout<<strcmp("abcd","abc")<<endl;
           cout<<strcmp("abc","abcd")<<endl;
           cout<<strcmp("abc","de")<<endl;
           cout<<strcmp("de","abc")<<endl;
           cout<<strcmp(" ","\n")<<endl;

          結果:

          0
          1
          -1
          0
          1
          -1
          -3
          3
          22
          Press any key to continue

          posted on 2008-09-04 13:31 so true 閱讀(618) 評論(0)  編輯  收藏 所屬分類: C&C++

          主站蜘蛛池模板: 金昌市| 吉隆县| 桐城市| 孟州市| 宜川县| 肥东县| 台北市| 平邑县| 伊通| 新安县| 靖江市| 县级市| 平谷区| 双辽市| 陆川县| 新兴县| 德庆县| 宜昌市| 原阳县| 枞阳县| 浮山县| 内丘县| 大厂| 江永县| 静安区| 和静县| 常宁市| 安泽县| 桂东县| 武乡县| 昭平县| 赣榆县| 个旧市| 辽中县| 阳江市| 土默特左旗| 克拉玛依市| 城固县| 繁峙县| 苏尼特右旗| 苍梧县|