Hello!
I have a problem. I have a program, that must convert entered binary number to integer. But this program fails. I have no idea, where should be the mistake.
Please help !
sorry for non englis program - it's in estonian, because my home language is estonian.
Code:
#include <stdio.h>
#include <math.h>
void bin_dec();
int main(){
while(1){
char otsus;
//Sissejuhatus ja valik
printf("Mis teisendust on vaja teha:\n");
printf("d - kahendsusteemist kumnendsusteemi\n");
printf("v - välju programmist.\n");
printf("Teie otsus: ");
scanf("%s", &otsus);
if(strcmp(&otsus, "d") == 0){
bin_dec();
}
else if(strcmp(&otsus, "v") == 0){
break;
}
else{
printf("Sisestasite sobimatu t2he.\n"); //t2he ehk tähe (täpitähti ta ei näita hästi)
}
printf("\n");
}
system("pause");
return 0;
}
//Teisendab kahendsüsteemist kümnendsüsteemi
void bin_dec(){
char jada[20];
int i;
int j = 0;
int arv = 0;
printf("Sisestage number (1'd ja 0'id): ");
scanf("%s", &jada);
printf("\nArv %s on kumnendsusteemis ", jada);
for(i = strlen(jada); i >= 0; i--){
arv = arv + atoi(jada[i]) * pow(2, j);
printf("%d", arv);
j++;
}
}