if( (*ptr != ',') || strlen(ptr+1) < sizeof(struct A) * num1)
{
printf("\n Condition satisfied.");
}
This is the code in question. I have a string of the format str = "-1,ABCDEFGH", and a struct A of size 15 bytes.
I'm performing this operation beforehand:
number = strtoul(str, &ptr, 10);
After this operation, ptr points to the ',' and number = -1
Looking at the IF condition, the first statement evaluates to be false (because *ptr = ',') and the second statement executes to be TRUE even though it should be false ( strlen(ptr+1) is positive, and (sizeof(struct A) * number) is negative, simply because num1 is a negative value ).
Why is this statement evaluating to be true and entering the IF block? I'm getting the output 'Condition satisfied', whereas I shouldn't be. Thanks in advance.