-
clearing a char* ??
I have a buffer called sendbuf. I am using it in a winsock program. It is set to the text the user entered, and then sent to the server. The problem is, that if a user types in "test" and then "a" the output would be "aest". I need to clear the sendbuf array so that it doesn't have leftover characters from the last input, but i cant figure out how!
sendbuf = ""; gets errors. :confused:
help would be nice :p
Thx in advance,
Glorfindel
-
Code:
strcpy( sendbuf, "" );
or, if you know the size of sendbuf,
Code:
memset( sendbuf, '\0', size_of_sendbuf );
-
hummm... perhaps the buffer being cleared isn't the issue. I have tried using those to clear it, but the output still will be "aest" with input of "test" and "a"...
Code:
char *sendbuf = new char[32];
while(strcmpi(sendbuf, "quit")) {
strcpy( sendbuf, "" );
cout<<"input:";
cin.getline(sendbuf, 32, '\n');
send( m_socket, (char*)sendbuf, strlen(sendbuf), 0 );
}
Thats the code. If sendbuf != to "quit" it should input new data, and send it to the server.
-
:D :D :D
The problem was that I was forgetting to clear the buffer on the server too! :eek:
Thanks for the help!