Reputation: 5415
All,
I come from java and php world so this maybe a factor. But I have a problem with:
printf("%s\n",data[0]);
if(data[0] == "BG01") {
printf("%s\n",otherstring);
}
The problem is that first printf returns in the console "BG01" but for some reason the IF condition doesn't pick up on it and the second printf never gets executed.
What's wrong with this picture?
Thanks, goe
Upvotes: 4
Views: 349
Reputation: 15925
The way you are doing it now is that you are comparing 2 pointers instead of the strings they point to. These pointers could point to the same value, but located in very different spots in memory and so be not true.
The way to do it is the use the strcmp(string1, string2) function which will check the strings themselves and not the pointers.
Upvotes: 12
Reputation: 992985
In C, you have to use strcmp()
, much like you have to use .equals()
in Java:
if (strcmp(data[0], "BG01") == 0) ...
Upvotes: 8