[問題] strcmp
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV C
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
請問一下, 老師說strcmp是從第一個字符開始比,
完全相同輸出0,
左>右,輸出 +的差值
右<左,輸出-的差值
為什麼我編譯後出現+1和-1, 不是+2,-2?
我有試過其它字符,它好像只會出現 0/1/-1 三種
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int delta1=strcmp("ABC","ABC");
printf("%d\n",delta1);
int delta2=strcmp("ABF","ABC");
printf("%d\n",delta2);
int delta3=strcmp("ABC","ABF");
printf("%d\n",delta3);
return 0;
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.181.59
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1439304012.A.5F5.html
※ 編輯: GooLoo (114.25.181.59), 08/11/2015 22:40:43
→
08/11 22:42, , 1F
08/11 22:42, 1F
→
08/11 22:49, , 2F
08/11 22:49, 2F
→
08/11 22:50, , 3F
08/11 22:50, 3F
推
08/12 01:04, , 4F
08/12 01:04, 4F
→
08/12 01:13, , 5F
08/12 01:13, 5F
→
08/12 12:53, , 6F
08/12 12:53, 6F