Go Down

Topic: Handling series of AT commands to GSM shield (Read 351 times) previous topic - next topic

surepic

Yes you can treat it as false in if statement.
If(strstr(char array,"string to find"))
Will evaluate true if string is found and if not found will evaluate false.


PaulS

#16
Sep 26, 2018, 12:17 pm Last Edit: Sep 26, 2018, 12:18 pm by PaulS
Quote
Source of my confusion is, that I've read "Dereferencing a null pointer is undefined behavior in C".
Dereferencing means using a pointer to accomplish something. You should only do that after testing that the pointer is not NULL. You can ALWAYS compare a pointer to NULL (explicitly or implicitly).

Explicit:
Code: [Select]
char *haystack = "Needles all over the place";
if(strstr("needle", haystack) == NULL)
{
   // No needle in that haystack
}


Implicit:
Code: [Select]
char *haystack = "Needles all over the place";
if(!strstr("needle", haystack))
{
   // No needle in that haystack
}
The art of getting good answers lies in asking good questions.

surepic

Strstr(actual string, string to search for)
So
Code: [Select]

If(!strstr("haystack",needle));

PaulS

Strstr(actual string, string to search for)
So
Code: [Select]

If(!strstr("haystack",needle));

Yeah, but that doesn't make any sense. 8)

Looking for a haystack in a needle?
The art of getting good answers lies in asking good questions.

surepic

#19
Sep 26, 2018, 01:01 pm Last Edit: Sep 26, 2018, 01:08 pm by surepic
Actual string is haystack. Needle is a string to be searched for. not opposite.

Char string[]="hello world";
Char needle[]="world";

Strstr(string,needle);

Thats what i meant.

But not strstr(needle,haystack).

Go Up