# Comparison is always false due to limited data type error help

• 02-16-2013
johnjrgs
Comparison is always false due to limited data type error help
Code:

```do   {   printf("Edit the entry's cellphone number:");         scanf("%s", addressbook[4][num]);         length = strlen(addressbook[4][num]); //gets the length of    the input (should be 10)         //checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively             for(i=0; i<11; i++){                 if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9') && (length=='11'))                 {                     flag = 1;                 break;                 } //end if                             else { //prints restrictions/parameters for the cellphone number                 printf("The format of the input is: 09xxyyyyyyy\nwherein x and y are integers from 0 -> 9\n");                 break; } //end else         }     }     while(flag!=1);```
why do I get an error here?

Code:

` if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9') && (length=='11'))`
And how do I fix this?

The error message is:
comparison is always false due to limited data type
• 02-16-2013
grumpy
You haven't really provided enough information, so I'm only guessing. In particular, the types of your variables are probably a contributor.

However, the culprit is probably the comparison "(length == '11')" at the end of that if statement. The value of the multi-character literal is implementation defined (not 11 in your case). If length is an unsigned type, and '11' yields a negative value, that test will always give a false result.

You might also want to look up the standard function isdigit() which is declared in <ctype.h>. It will simplify your code.

The fact you have "break" statements in both the if and else blocks means the for loop will not iterate 11 times.