Skip to main content
Visitor II
March 23, 2013
Question

Cosmic compiler and strcmp

  • March 23, 2013
  • 2 replies
  • 821 views
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){
}

    This topic has been closed for replies.

    2 replies

    Visitor II
    March 25, 2013
    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.

    klaasdcAuthor
    Visitor II
    March 26, 2013
    Posted on March 26, 2013 at 08:00

    Aha, didn't know it returned 16 bit.

    I'll try that, thank you!