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