Extra Characters

This is a discussion on Extra Characters within the C++ Programming forums, part of the General Programming Boards category; I'm using the code below to send messages between the through the two programs.
It works, but I'm getting a ...

Extra Characters

I'm using the code below to send messages between the through the two programs.
It works, but I'm getting a lot of excess characters and I have no idea where they came from...http://i56.tinypic.com/5by613.png

So the client gets input from the user, puts it into char buffer[], and sends it to the server. So far so good. The server notices that a message is waiting (exciting! perhaps his crush is sending a message!) and gets it from the mysterious socket interface. So far, so good. Then the server, wanting to read the message, appends a ' ' to the message. Wait, what? If ' ' signifies the end of a string, how does one send messages with spaces, like "C uses null-terminated strings"?

So the client gets input from the user, puts it into char buffer[], and sends it to the server. So far so good. The server notices that a message is waiting (exciting! perhaps his crush is sending a message!) and gets it from the mysterious socket interface. So far, so good. Then the server, wanting to read the message, appends a ' ' to the message. Wait, what? If ' ' signifies the end of a string, how does one send messages with spaces, like "C uses null-terminated strings"?

Change that ' ' to a (char) 0 or a '\0' and that should fix it.

oh my.. sorry for this thread, i really should've seen that. thanks for the explanation though.

Originally Posted by rags_to_riches

And please DON'T USE gets!!!

okay.. i used scanf instead. can i ask why not though? and whether scanf is the most appropriate alternative?