The +1 will cause the zero at the end of the string (after the newline) to be transmitted, which means that when you print the buffer on the other end, printf
stops after the first line. You don't really want to send that zero, I think, so don't do that...
If you really want the zero at the end of the string through the pipe, you will have to then figure out where each string ends, and print them individually, e.g. using strlen()
to figure out how long the message is, and use an index that moves index += strlen(&message[index])+1
, and printf("%s", &message[index]);
in a loop until you have printed all (compared index with how much you've read!).
Using a loop until read
returns zero bytes should allow you to read all the input (you are reading too short right now, that's why you're not getting all the 9's).