hi this is my code. The code should convert binary numbers to decimal but it doesn't...can any1 please check where i could have gone wrong.
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char s[40];
int base;
int index,n,p,sum=0; /*n is the number of digits in the converted value*/
printf("enter the number and base: ");
scanf("%s %d",s,&base);
for(n=strlen(s)-1;n>=0;n--)
{
p=strlen(s);
for(index=strlen(s)-(p-1); index<=p; index++)
sum += s[index] * pow(base,n);
}
printf("%d",sum);
printf("\n");
}