removing last char only when it's newline

This commit is contained in:
Václav Šmejkal 2023-03-25 17:50:19 +01:00
parent 7359c678d4
commit 85834544aa
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -242,8 +242,9 @@ void why2_send_socket(char *text, char *username, int socket)
char *text_copy = why2_calloc(length_buffer, sizeof(char)); char *text_copy = why2_calloc(length_buffer, sizeof(char));
struct json_object *json = json_tokener_parse("{}"); struct json_object *json = json_tokener_parse("{}");
//COPY text INTO text_copy WITHOUT LAST CHARACTER //COPY text INTO text_copy (WITHOUT LAST CHARACTER WHEN NEWLINE IS AT THE END)
strncpy(text_copy, text, length_buffer - 1); if (text[length_buffer - 1] == '\n') length_buffer--;
strncpy(text_copy, text, length_buffer);
//ADD OBJECTS //ADD OBJECTS
json_object_object_add(json, "message", json_object_new_string(text_copy)); json_object_object_add(json, "message", json_object_new_string(text_copy));