Hello guys, I am new to this forum, but I am sure I will be an active one as I am a computer science major. I am still kindof new to c programming and am hitting a major issue.
I am writing a echo client server code and I am trying to make my program do arithmetic and to do so I need to change a characters called buf in my code to integers and them add them and save them back as characters and stdout them. Another problem is what if sum is larger than 1 char, what would I do to make it save say 13 in buf[0] = 1 and buf[1]=3.
If there is another way around this please tell me!
Here is my piece I am working on any suggestions are much appreciated.
if (buf[1] == '+')
{
one= atoi(&buf[0]);
two = atoi(&buf[2]);
sum = (one + two);
buf[0] = itoa(sum); // THIS DOES NOT WORK HELP!!!
Rio_writen(connfd, buf, n);
}
To explain this a bit more. Rio_written is (the connection, the buf array of characters, and then size or bytes of what was inputted).
so I am not sure this is still right because I can't get it to work, but I think I am on the right track!!
by the way the reason I want to convert it back into characters is because i would have to edit all of my code. I thought it would just be easier to put it back in char.