title: Saving binary numbers from char type into an array to use them later
body: <p>I have to do a homework. Following task:</p>
  
  <p>First you are asked, how many binary numbers you want to type - you can only type between 1 to 5 binaries, everything else will cause an error.<br>
  The input is a binary number (e.g. 01011011) which must consist of 8 digits (so 1010 or 1000010000 would be false).<br>
  After entering the 8 digits binary number, we have to save the typed in binary number from the user.</p>
  
  <p>My Code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  int main () {
  
  char c,input[8];
  int s2,amount,y=0,s3;
  int s=0,i[s];
  
  printf("How many binary numbers? ");
  scanf("%i",&amp;amount);
  
  while(amount &lt; 1||amount &gt; 5) {
    printf("F A I L U R E\n");        
    printf("How many binary numbers? ");
    scanf("%i",&amp;amount);
    if(amount &gt;= 1 &amp;&amp; amount&lt;=5) {
    break;
    }
  }
  
  for(s3=1;s3&lt;=amount;s3++){
      L0:
      printf("Please enter binary Number (8 digits): ");
          for(s2=0;s2&lt;=8;s2++) {
          c = getche();
              if(c=='0'||c=='1') {
                  y=1;}
              else
                  y=0;
  
          if(y==1) { 
  
              if(s2==7) {
                  input[s2]=c;
                  input[8]='\0';
              break;}
  
              else
                  input[s2]=c;}
  
          else if(y==0) {
              break;}
  }
  
  if(y==0) {
      input[0]='\0';
      printf("\n");
      printf("F A I L U R E: Incorrect Input\n");    
      goto L0;
      }
  else
      //Now save the binary numbers in a variable
      //Tried:
  
      sscanf(input,"%i",&amp;i[s]);
      printf("\nBinary number is saved: %i\n\n",i[s]);
      s++;
      //Problem: if 000100100 --&gt; makes do Octal because of leading 0
      //for example if input is 01110011 -&gt; Output is:
      //if there is no leading 0, it works
  }
  //Just for testing, if it was rly saved - two inputs.. - works
  printf("The first saved binary was: %i\n",i[0]);
  printf("The second saved binary was: %i\n",i[1]);
  
  }
  </code></pre>
  
  <p>I used the <code>sscanf()</code> function to save the input and it works, but not if the number has a leading zero (e.g. 01101100 turns to 295488) - this is because C interprets numbers with a leading 0 as octal. So I don't know how I can get rid of this problem. I left a picture of the terminal output to show you the problem.<a href="https://i.stack.imgur.com/l9sIg.png)" rel="nofollow noreferrer">Image-Example</a></p>
  
  <p>Would anyone have an idea how can I save the written binary number into an array variable without getting an octal number? Or is there another way without <code>sscanf()</code>?</p>