How to print multiple lines to stdout with read() with a client in C
<p>I wrote a simple server (more like a remote-shell) and it works fine using telnet.</p>

<p>Now I want to write the client and get the output of the server. The client connects fine and I see my prompt. But then it fails. My idea is:
Read from stdin, send it to the server, receive the ouput from server (as already shown in so many tutorials). But my code fails to do it, especially if it comes to longer outputs, like ping -c3 www.google.de</p>

<p>EDIT:
thanks to the comments from EOF and iharob i rewrote the code and at least I don't get any SegFaults anymore (I wasn't aware that read don't adds an '\0').</p>

<pre><code>fputs(output, stdout);
memset(output, 0, MAX);
while(1){
    fgets(input, MAX, stdin); 
    write(sock, input, strlen(input))

    /* receive answer from server */
    r = read(sock, output, MAX))
        output[r] = '\0';
        fputs(output, stdout);
        memset(output, 0, MAX);

    /* then print the prompt again
       if you remove this part, you can hit enter without a cmd and have
       the prompt back again. but then you have to hit enter after each 
       cmd. so there has to be another way*/
    r = read(sock, output, MAX)
        output[r] = '\0';
        fputs(output, stdout);
        memset(output, 0, MAX);
}
</code></pre>

<p>So how do I accomplish to get the whole output from the server?</p>