Mantero - 2011-11-17

Ok so I tryed to make a program in which i could enter any binary number and
transform it into a octal number (example. "111" would be "7").
So my code is bellow and I hope you are able to understand it and solve my
problem, ty in advance.

#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <string.h>
main()
{
      int b[100],n,i,j,k,l;
      char a[100];
      L1:printf("Unesite binarni broj: ");
      gets(a);
      n=strlen(a);
      for(i=0;i<n;i++)
      {
                      if(a[i]!='1' && a[i]!='0') goto L1;
                      }
      for(i=n-1,k=n-2,l=n-3,j=0;n>0;n--,j++)
      {
                        if(a[l]=='1')
                        {
                                       if(a[k]=='1')
                                       {
                                                       if(a[i]=='1') b[j]=7;
                                                       else b[j]=6;
                                                       }
                                       else
                                       { 
                                                       if(a[i]=='1') b[j]=5;
                                                       else b[j]=4;
                                                       }
                                       }
                        else
                        {
                                       if(a[k]=='1') 
                                       {
                                                      if(a[i]=='1') b[j]=3;
                                                      else b[j]=2;
                                                      }
                                       else
                                       {
                                                      if(a[i]=='1') b[j]=1;
                                                      else b[j]=0;
                                                      }
                                       }
      for(i=0;i<=j;i++)
      {
                       printf("%d",b[i]);
                       }
      getch();
}