I have a string that looks like this:
"show net\r\r\nSSid=roving1\r\nChan=1\r\nAssoc=FAIL\r\nRate=12, 24Mb\r\nAuth=FAIL\r\nMode=NONE\r\nDHCP=FAIL\r\nBoot=0\r\nTime=OK\r\nLinks=0\r\n<4.00> "
This is data I receive from a peripheral device and I want to scan it for the string "Auth=FAIL". I'm querying it using the following command:
res = strstr(uart_rd, "Auth=FAIL");
however, it returns a value of 0. But if I simply issue the command:
res = strstr("nnAuth=FAILn", "Auth=FAIL");
it returns a value. What could be going wrong when it tries to search my char array uart_rd?
EDIT:
It looks like the issue was with a memset I was doing to clear the array before putting new data into it. I was filling it with 0s using the command:
memset(uart_rd,0,sizeof(uart_rd));
whereas I've now changed it to
memset(uart_rd,"",sizeof(uart_rd));
and it all seems to be working. Thanks for the help in diagnosing where my problem was though!
uart_rddeclared?strstr()certainly does work. If it can't find the substring in your array, then the substring isn't there. Maybe an encoding issue, or you accidentally pasted "invisible" characters either in the haystack or in the needle, or perhaps you have some other error at another place in your code (e. g. a buffer overflow that overwrites the contents of your array or whatnot).