I am trying to search two different strings in a line using strstr.
sBuffer = "This is app test"
s1= strstr (sBuffer, "This");
s2= strstr (sBuffer, "test");
printf("%s\n", s1); //prints - This is app test
printf("%s\n", s2); //prints - test
if (s1 && s2)
//do something
Expected output for s1 should be the string "This"
but it is printing the entire string for s1.
s2 however is printed correctly.
Any help appreciated.
EDIT: Although all the answers are correct (upvoted all answers), I am accepting dasblinkenlight's answer. This is because I realize checking the boolean condition as shown below would suffice my requirement. Thanks for all the answers.
if ( (strstr (sBuffer, "This")) && (strstr (sBuffer, "test")) )
//do something