This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Null terminating character

Hi all,

I've this strange problem with the \0 character.
I'll show you the code first:

#include <REG52.H>

void test(char *s)
{
        int idx;

        for(idx = 0; *s != '\0'; idx++, s++)
        {
        }

        P1 = idx; // Led's are connected to P1 so i can see the idx value.
}

void main()
{
        test("12345");

        while(1);
}

Now the problem:
When i call the test function with 4 characters or less, the condition

*s != '\0'

does not work. The led's show me a value of 0x63 when i call the test function with 1, 2, 3 or 4 characters. There's no problem when i call the test function with 5 characters or more. The led's show me 0x05 with a call of 5 characters.

I've also tested this code with the SDCC compiler and the call with 4 characters or less did worked like it should.

I'm working with the C51 COMPILER V8.05a

Any ideas? Thanks!

0