feat : unescape carriage returns on client

This commit is contained in:
2025-03-01 12:46:56 +01:00
parent db964493c2
commit 3c770e4ea4
2 changed files with 29 additions and 1 deletions
+28
View File
@@ -7,7 +7,34 @@
#include <sys/socket.h>
#include <unistd.h> // read(), write(), close()
#include <errno.h>
#include <stdbool.h>
#include "config.h"
void unescape(char *buffer, size_t buf_len)
{
int i;
bool last_is_escape = false;
for (i = 0; i < buf_len; i++)
{
if (last_is_escape)
{
switch (buffer[i])
{
case 'n':
buffer[i - 1] = ' ';
buffer[i] = '\n';
}
}
if (buffer[i] == '\\')
{
last_is_escape = true;
}
else
{
last_is_escape = false;
}
}
}
int main()
{
@@ -43,6 +70,7 @@ int main()
// function for chat
char clientMessage[MESSAGE_STRING_LENGTH] = {0};
recvfrom(sockfd, clientMessage, MESSAGE_STRING_LENGTH, 0, servaddr, &ss);
unescape(clientMessage, (size_t)MESSAGE_STRING_LENGTH);
puts(clientMessage);
// close the socket
+1 -1
View File
@@ -1 +1 @@
première ligne \n Deuxième ligne \n troixième ligne
première ligne\nDeuxième ligne\ntroixième ligne