Is a string a bit string
Ultimately, you are looking to see if any character is not either '0' or '1'.  The moment you find such a character, you can break the loop immediately: 

int isBitString = 1;
for(int i = 0; i &lt; len2; i++) {
    if (str[i] != '0' &amp;&amp; str[i] != '1') {
        isBitString = 0;
        break;
    }
}