12-21-2018 03:49 AM - edited 12-21-2018 03:50 AM
Hello
im using if loop for comparing a char and making decision, but if condition is not working
here is my code
strncpy(BufString, &readBuf[0], 3); BufString[3] = '\0'; Fmt (outMessage, "%s<%s%s%s","Power supply \"",BufString,"\" "); MessagePopup ("Status", outMessage); if (BufString == 'VOL') { Fmt (outMessage, "%s<%s%s%s","Power supply \"", BufString, "\" "); MessagePopup ("Status", outMessage); }
though value of BufString is VOL, condition inside if loop dosnt execute
12-21-2018 04:22 AM
In ANSI C, strings cannot be compared with == operator.
You need to use the strcmp function.
12-21-2018 04:26 AM
@ebalci
can you just post a simple example code to use strcmp instead of "=="
12-21-2018 04:59 AM
This is how you do it
if (strcmp (BufString,"VOL")==0)
where BufString is my string to be compared, and VOL is my Constant
I found it from Stack Overflow