cancel
Showing results for 
Search instead for 
Did you mean: 

Cosmic compiler and strcmp

klaasdc
Associate II
Posted on March 23, 2013 at 18:04

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){
}

2 REPLIES 2
luca239955_stm1_st
Senior II
Posted on March 25, 2013 at 11:15

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.

klaasdc
Associate II
Posted on March 26, 2013 at 08:00

Aha, didn't know it returned 16 bit.

I'll try that, thank you!