character string ouput problem

Character string problem!

Posted 05 February 2010 - 10:54 PM

Hi all! I am having a problem with a networking program I am putting together. I send a char* string to a server and print it out using cout. The problem is when I go to print out the char* string it comes out as "My message###############*&^^$%%$###", it displays my message with a bunch of funny symbols at the end.

Replies To: Character string problem!

Re: Character string problem!

Posted 05 February 2010 - 10:59 PM

Have you tried stepping through your code with a debugger and looking at what is actually stored in packet.text?

I don't know anything about sockets so I'm not going to pretend I do but, I had problems similar to this where extra characters would print out. Look and see what I being stored in the packet variable first.

Also, dont forget to use code tags when posting code. It makes it much easier to read.
( Code Tags are the little <> brackets in the toolbar )

Re: Character string problem!

Posted 05 February 2010 - 11:10 PM

eker676, on 05 February 2010 - 09:59 PM, said:

Have you tried stepping through your code with a debugger and looking at what is actually stored in packet.text?

I don't know anything about sockets so I'm not going to pretend I do but, I had problems similar to this where extra characters would print out. Look and see what I being stored in the packet variable first.

Also, dont forget to use code tags when posting code. It makes it much easier to read.
( Code Tags are the little <> brackets in the toolbar )

sorry about the formatting, I have never used this site before. Its not a network code problem at all, it is a char* string problem. I think it has something to do with the struct text member being 80 bytes and the data coming in being less.

I am guessing this.I think it should be strlen(sendData)+1...that will include the null character.So you you wont have problems on the recieving end.

You were right! is was just missing the terminating "\0" character. Adding 1 to the length of the string got it in there and it displays right. Thanks for your help and everyone elses who tried. It was a simple thing as it usualy is. Thanks again!