From 85834544aa02758229dd0c7a9f7ceda9c7019838 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 25 Mar 2023 17:50:19 +0100 Subject: [PATCH] removing last char only when it's newline --- src/chat/misc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index acaa496..53f4b91 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -242,8 +242,9 @@ void why2_send_socket(char *text, char *username, int socket) char *text_copy = why2_calloc(length_buffer, sizeof(char)); struct json_object *json = json_tokener_parse("{}"); - //COPY text INTO text_copy WITHOUT LAST CHARACTER - strncpy(text_copy, text, length_buffer - 1); + //COPY text INTO text_copy (WITHOUT LAST CHARACTER WHEN NEWLINE IS AT THE END) + if (text[length_buffer - 1] == '\n') length_buffer--; + strncpy(text_copy, text, length_buffer); //ADD OBJECTS json_object_object_add(json, "message", json_object_new_string(text_copy));