Analyzing buffer text

Hi Guys !

i don't know how to analyze buffer text, getting from user, here is my code don't know where is the problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

		// here i'm getting and reading text from the user		
		bzero(buffer, 1024);
		read(m_Socket, buffer, 1023);
		string inputText;
		inputText = string(buffer);
                
                // here i'm converting to string btw is it necessary to convert?		
		string userCommand = inputText.c_str();	
		strcpy(buffer, inputText.c_str());
		write(m_Socket, buffer, sizeof(buffer));	
		
		
		// And this part is not working, i have done everything that was necessary for it
		if (userCommand.compare("help")){
			inputText += "You typed help\n";
				
			cout<< "Help"<<endl;			
		} else{
			cout<< "Not Help"<<endl;				
		}


Anyone can point out the mistake and provide some hint?

Thanks in advance

Regards,

Ewa
std::string::compare returns 0 if the two strings are equal so line 15 should be
if (userCommand.compare("help") == 0) {

You can also use operator== to compare the strings.
if (userCommand == "help") {
Hi Peter87 !

Thanks for help and reply, just wondering how to give vote or to like someone's post, because your post was helpful.

Thanks once again

Sincere Regards,

Ewa
Last edited on
Topic archived. No new replies allowed.