[問題] 程式小bug

看板C_and_CPP (C/C++)作者 (深藍)時間13年前 (2012/11/06 12:15), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
想請問各位大大~我在compile這個程式的時候發生錯誤~ 這行 n=strcmp(str2, str4); 錯誤原因是invalid conversion from `int*' to `int' 想請問這行要怎改才好~麻煩各位了~感恩^^~ 以下為程式原碼~ #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { char str2[]="Apple iPod"; char str4[]="Apple iPad"; int n; n=strcmp(str2, str4); if (n>0) { printf("%s大於%s\n", str2, str4); } else if (n==0) { printf("%s等於%s\n", str2, str4); } else { printf("%s小於%s\n", str2, str4); } ===> n=strncmp(str2,str4,5); if (n>0) { printf("%s前五個字元大於%s前五個字元\n", str2, str4); } else if (n==0) { printf("%s前五個字元等於%s前五個字元\n", str2, str4); } else { printf("%s前五個字元小於%s前五個字元\n", str2, str4); } system("PAUSE"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.30.208.127

11/06 13:06, , 1F

11/06 13:07, , 2F
我想問題可能不是出在程式碼上面。
11/06 13:07, 2F

11/06 14:44, , 3F
瞭解了~感謝^^~
11/06 14:44, 3F
文章代碼(AID): #1Gc8xtqH (C_and_CPP)
文章代碼(AID): #1Gc8xtqH (C_and_CPP)