i have a linked list set up like
typedef struct client_list {
char *client_name;
int client_socket_fd;
struct client_list *next;
} client;
client *client_list=NULL;
before adding to the list i check if it already exists, only if it does not then i add
if (client_list==NULL || already_there(client_list, buffer)==0) {
client_list = add_client(buffer, client_list, i);
}
int already_there(client *client_list, char *username) {
if (client_list == NULL) return(0);
else if (strcmp(client_list->client_name, username)==0) return(1);
else return already_there(client_list->next, username);
}
client *add_client(char *username, client *client_list, int client_socket_fd) {
client *new_client = (client *)malloc(sizeof(client));
new_client->client_name = username;
new_client->client_socket_fd = client_socket_fd;
new_client->next = client_list;
return new_client;
}
it adds the client the first time, but then the next time, always detects that the new client is already there...
somehow strcmp is always resulting true after the first time...