LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

String comparison CVI If loop

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

0 Kudos
Message 1 of 4
(2,847 Views)

In ANSI C, strings cannot be compared with == operator. 

You need to use the strcmp function. 

S. Eren BALCI
IMESTEK
Message 2 of 4
(2,835 Views)

@ebalci

can you just post a simple example code to use strcmp instead of "=="

0 Kudos
Message 3 of 4
(2,829 Views)

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

0 Kudos
Message 4 of 4
(2,822 Views)