> Victor Bazarov wrote:
>> Index wrote:
[receiving data with recv, trying to compare with c-string]
>>> ** Though I typed q, the received message has a junk charecter at its
>>> end and hence the comparison dosn't work.but sometimes after two/three
>>> failed times, the string is without any junk charecter.
>> You need to use 'strncmp' or simply compare the first character of
>> the message:
>>
>> if (message[0]=='q') {
>> Close(clntSocket);
>> exit(0);
>> }
>>
>> Note the single quotes around the q.
Index wrote:
> but if the message starts with q but has more characters after it?If I
> compare only teh first charecter, it will not be appropriate.
Please don't top-post in this group. See the link in my signature.
The problem is, that you don't send/receive null-terminated strings. Either
null-terminate the received buffer before comparing, or compare with
strncmp and give as length parameter the number of received bytes.
--
Thomas
http://www.netmeister.org/news/learn2quote.html