Here is the code in cleaned form:
http://hastebin.com/yikuxakegu.c

Notice, I used str_len(str) + 1 for the size. The null byte is important, though you usually don't send it with your string. If you append it on the receiving end, or just send it together with everything else, is up to you. Important is that the null byte is present.

In general it appears like you are missing some knowledge about pointers and memory allocations in general. I would urge you to fill these knowledge gaps before you end up with code that crashes all over the place and is hard to debug, or a program that just leaks memory like there is no tomorrow.


His words are wise, his face is beard.