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 閱讀(611) 評論(0)  編輯  收藏 所屬分類: C&C++

          主站蜘蛛池模板: 和平县| 丹凤县| 江北区| 满城县| 嵊州市| 革吉县| 日喀则市| 宽城| 五台县| 安龙县| 炎陵县| 平泉县| 宜兰县| 长沙县| 孝义市| 贵港市| 灌南县| 江津市| 辽阳县| 南岸区| 新营市| 崇明县| 延川县| 静海县| 安福县| 开封县| 手机| 彩票| 伊春市| 双鸭山市| 仁怀市| 尼木县| 叶城县| 汉阴县| 沙湾县| 仪陇县| 曲水县| 九龙县| 克东县| 晋中市| 周至县|