0
我想對字符串數組進行排序,但是我的編譯器總是說我在賦值中有不兼容的類型。賦值中的不兼容類型 - C
下面是有問題的代碼。
for(i = 0; i < 499; i++) {
max = 0;
for(j = 1; j < 500; j++) {
if(strncmp(user_id[max], user_id[j], 9) > 0) {
printf("max = %s, j = %s\n", user_id[max], user_id[j]);
temp = user_id[j];
user_id[j] = user_id[max];
user_id[max] = temp;
}
}
}
下面兩行拋出錯誤:
user_id[j] = user_id[max];
user_id[max] = temp;
爲什麼,我收到此錯誤?編輯: 對不起,我忘了包括之前。
char user_id[500][9];
char* temp;
i j and max are int.
rover-208-149:prog3 kubiej21$ gcc --ansi --pedantic -o prog3 prog3.c
prog3.c: In function ‘main’:
prog3.c:46: error: incompatible types in assignment
prog3.c:47: error: incompatible types in assignment
由於您的代碼段不包含'user_id'或'temp'的定義,也沒有發佈確切的錯誤消息,所以不可能說。 – 2012-03-30 01:44:11
「i」,「j」,「max」,「user_id」,「temp」等的定義在哪裏?什麼是實際的錯誤信息? – 2012-03-30 01:44:43
請告訴我們你的user_id數組和temp變量是什麼類型。如果你的編譯器告訴你它是不兼容的類型,那就意味着它們不匹配。 – grifos 2012-03-30 01:45:01