From 72ee99e84838e3b0c74e3d66defdcc3ab7f4f6f9 Mon Sep 17 00:00:00 2001 From: naxuroqa Date: Wed, 14 Aug 2013 10:44:25 +0200 Subject: rewrite of get_id function --- testing/nTox.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/testing/nTox.c b/testing/nTox.c index cab2d158..ead4fd21 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -52,28 +52,15 @@ uint8_t num_requests = 0; void get_id(Messenger *m, char *data) { - char idstring0[200]; - char idstring1[FRIEND_ADDRESS_SIZE][5]; - char idstring2[FRIEND_ADDRESS_SIZE][5]; + sprintf(data, "[i] ID: "); + int offset = strlen(data); int i = 0; uint8_t address[FRIEND_ADDRESS_SIZE]; getaddress(m, address); - for(i = 0; i < FRIEND_ADDRESS_SIZE; i++) + for(; i < FRIEND_ADDRESS_SIZE; i++) { - if (address[i] < (FRIEND_ADDRESS_SIZE / 2)) - strcpy(idstring1[i],"0"); - else - strcpy(idstring1[i], ""); - sprintf(idstring2[i], "%hhX",address[i]); + sprintf(data + 2*i + offset, "%02X ", address[i]); } - strcpy(idstring0,"[i] ID: "); - int j = 0; - for (j = 0; j < FRIEND_ADDRESS_SIZE; j++) { - strcat(idstring0,idstring1[j]); - strcat(idstring0,idstring2[j]); - } - - memcpy(data, idstring0, strlen(idstring0)); } void new_lines(char *line) -- cgit v1.2.3