Fenomatik Fenomatik - 8 months ago 45
C Question

Condition not meeting in c

For some reason this condition is not passing as true even tho the variable watch is showing var equal.enter image description here

if(arr[r1][1] != NULL) {
t_plat = arr[r1][1];
t_ver = arr[r1][2];

if((arr[r2][1] == t_plat) && (arr[r2][2] == t_ver))

Answer Source

As you can see yourself from the screenshot the object arr[r2][1] stores value 0xb01a70 while the object t_plat stores value 0xb01770.

Thus if you compare the values stored in these objects like

if((arr[r2][1] == t_plat) )

you will get false without doubts. The values are unequal each other.

What are these values? They are pointers to first characters of strings. If you want to compare the strings themselves pointed to by the pointers you have to use standard C function strcmp declared in header <string.h>.

Thus you should write

if( strcmp( arr[r2][1], t_plat ) == 0 && strcmp( arr[r2][2], t_ver ) == 0 )