I'm building a multi-threaded network chat program, but I can't figure out how to pass variables into pthread_create.
I have the following line of code that creates a thread:
pthread_create(&thread, NULL, receive, (void *) socket_fd);
My receive function looks like this:
void * receive(void * socket) {
int socket_fd, response;
char message[MESSAGE_BUFFER];
socket_fd = (int) socket;
while(true) {
response = recvfrom(socket_fd, message, MESSAGE_BUFFER, 0, NULL, NULL);
if (response) {
printf("\nServer> %s", message);
printf("%s", prompt);
}
}
}
How can I pass a prompt variable into this receive function, when calling receive in pthread_create?
struct? Just see the example here.