 <p>change</p> <pre><code>strcat(ipstr,&amp;ipch); </code></pre> <p>to</p> <pre><code>strncat(ipstr, &amp;ipch, 1); </code></pre> <p>this will force appending only one byte from <code>ipch</code>. <code>strcat()</code> will continue appending some bytes, since there's no null termination character after the char you are appending. as others said, strcat might find somewhere in memory <code>\0</code> and then terminate, but if not, it can result in segfault. <br><br> from manpage:</p> <pre><code>char *strncat(char *dest, const char *src, size_t n); </code></pre> <p>The strncat() function is similar to strcat(), except that</p> <ul> <li>it will use at most n characters from src; and</li> <li>src does not need to be null-terminated if it contains n or more characters.</li> </ul>