William Gaatjes
Lifer
Since i am more in the hardware than in the software, i still make stupid mistakes in programming. Since i am programming a small microcontroller and it has no string.h or stdio.h libraries, i had to come up with my own string compare.
Sadly, it always returns 1.
I am tired, i do not see it anymore. What have i done wrong ?
Sadly, it always returns 1.
I am tired, i do not see it anymore. What have i done wrong ?
Code:
uint8_t StrCmp(uint8_t *strptr1, uint8_t *strptr2)
{
uint8_t returnvalue;
uint8_t safeguard;
safeguard = 0;
returnvalue = 1;
while((*strptr1 != 0x00) && (*strptr2 != 0x00))
{
safeguard++;
if(*strptr1 == *strptr2)
{
strptr1++;
strptr2++;
}
else
{
returnvalue = 0;
}
if(safeguard == 255)
{
returnvalue = 0;
break;
}
}
return (returnvalue);
}