Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

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
  • 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