2013-03-23 10:04 AM
I'm trying to compare an input string, and using the COSMIC C environment. I've had no luck with their supplied strcmp function, so I gave up and wrote my own...
But still wondering what is wrong... Here is the test case, when I run it, the result of strcmp is always zero: Anyone has an idea?u8 result;
result = strcmp(''A\0'', ''A\0'');
if (result != 0){
SerialPutString(''A=A Not zero\n'');
} else {
SerialPutString(''A=A Zero\n'');
}
result = strcmp(''A\0'', ''B\0'');
if (result != 0){
SerialPutString(''A=B Not zero\n'');
} else {
SerialPutString(''A=B Zero\n'');
}
while(1){
}
2013-03-25 03:15 AM
Hello,
strcmp returns an int: in your example the int returned is 0xFF00 and, when you cast it to a char, you loose the useful information in it. If you use an int instead of a char your code will work as expected. Regards.2013-03-26 12:00 AM
Aha, didn't know it returned 16 bit.
I'll try that, thank you!