Can anyone help me with my code?!

I need to do a programm binary to decimal converter without using library, just stdio.h

my code works wrong

```
void bin2dec(){
long int n;
int s=1,j,p=1,i=0,x;
int digit=1;
printf("Input a binary number: ");
scanf("%ld",&n);
while(digit==1)
{
x=n%10;
s=s+pow(2,i);
i=i+1;
n=n/10;
if(n==0)
digit=0;
}
printf("\nDecimal equivalent = %d",s);
for(j=1;j<=i;j++)
p = p*2;
}
```

And this is a power function

```
int pow(int b,int z){
int result=1;
while (z>0) {
result=result*b;
z--;
}
return result;
}
```

what's wrong???