From 5b4ad86b2670610694f573f01783addaa0168214 Mon Sep 17 00:00:00 2001 From: Dane MacFadden Date: Tue, 15 Jul 2025 12:08:37 -0600 Subject: [PATCH] fixed pointer issue --- main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index b39a0c8..40cdea5 100644 --- a/main.c +++ b/main.c @@ -27,11 +27,13 @@ int sockfd, confd; void *input(void *arg) { char msg[30]; + char *copy = malloc(31); while (1) { printf("Type a message: "); - fgets(msg, sizeof(msg), stdin); + fgets(msg, sizeof(msg), stdin); + strcpy(copy, msg); pthread_mutex_lock(&sendmut); - ListAppend(sendlist, &msg); + ListAppend(sendlist, copy); pthread_mutex_unlock(&sendmut); } return 0; @@ -57,11 +59,14 @@ void *sender(void *arg) { void *receiver(void *arg) { char msg[30]; + char *copy = malloc(31); while (1) { recv(sockfd, msg, 30, 0); - pthread_mutex_lock(&receivemut); - ListAppend(receivelist, msg); - pthread_mutex_unlock(&receivemut); + if (msg[0] != '\n' && msg[0] != '\0') { + pthread_mutex_lock(&receivemut); + ListAppend(receivelist, msg); + pthread_mutex_unlock(&receivemut); + } } return 0; }