struct Users{
int id;
char msg[];
};
int nUsers;
struct Users users[10];
void connectUser(struct Users user){
if(nUsers<10){
for(int i=0;i<10;i++){
if(users[i]==NULL){
users[i]=user;
printf("user %d connected!\n", user.id);
nUsers++;
}
}
}else
printf("number of users reached!\n");
}
這是我的代碼,當我嘗試編譯,自帶錯誤:惱人的問題與結構用C
[[email protected] ~]$ gcc -std=c99 socketserver.c -o socketserver
socketserver.c: In function ‘connectUser’:
socketserver.c:24: error: invalid operands to binary == (have ‘struct Users’ and ‘void *’)
socketserver.c:21: note: The ABI of passing struct with a flexible array member has changed in GCC 4.4
socketserver.c: In function ‘disconnectUser’:
socketserver.c:37: error: incompatible types when assigning to type ‘struct Users’ from type ‘void *’
每次我嘗試編譯,這些錯誤出現。你們能幫我嗎?
刪除'如果(用戶[I] == NULL)'。另一個錯誤是在'disconnectuser'中。哦。從'disconnectuser'中刪除'users [i] = NULL'。 'NULL'用於指針。你不能用'NULL'分配/比較'users [i]'(哪個*不是一個指針)。 –