string compare always true

Help
slenk
2013-08-09
2013-08-12
  • slenk

    slenk - 2013-08-09

    strcmp always returning positive

    ~~~~~~

    include <string.h>

    include <stdlib.h>

    ifdef linux

    include <stdio.h>

    endif

    void main(void)
    {

    char a[2]="b";

    if (strcmp(a,"cfr")
    {
    drawdot2();
    }

    ifdef linux

    printf("end");

    else

    while(1)
    {}

    endif

    }

    void drawdot()
    {

    ifdef linux

    printf("drawdot");

    else

    asm
    LD A,#0xFF
    LD HL,#0x4000
    LD (HL),A
    endasm;

    endif

    }
    void drawdot2()
    {

    ifdef linux

    printf("drawdot2");

    else

    asm
    LD A,#0xF
    LD HL,#0x4000
    LD (HL),A
    endasm;

    endif

    }
    ~~~

     
    Last edit: slenk 2013-08-09
  • Philipp Klaus Krause

    I don't see the problem here. strcmp() returns zero, if the strings are identical, non-zero otherwise. Non-zero is interpreted as true for the if.

    Philipp

     

Log in to post a comment.