[問題] 程式小bug
想請問各位大大~我在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:06, 1F
→
11/06 13:07, , 2F
11/06 13:07, 2F
→
11/06 14:44, , 3F
11/06 14:44, 3F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章