+ 6

Why does this code give me no output on code playground?

#include <stdio.h> #include <math.h> int main() { char *binstr="0100110"; int binlen=strlen(binstr); int i=binlen-1; int res=0; while(i>=0){ res+=atoi(binstr[i]) *pow(2,binlen-1-i); i--; } printf("%d",res); return 0; }

4th Dec 2018, 12:04 AM
Sonic
Sonic - avatar
6 Answers
4th Dec 2018, 2:16 AM
Sonic
Sonic - avatar
+ 4
Yes Gaurav Maheshwari I have posted the new version here. https://code.sololearn.com/c5My5HO725AH/?ref=app Pro Coder is this code good for what you asked me?
4th Dec 2018, 2:47 AM
Sonic
Sonic - avatar
+ 4
Yes!
4th Dec 2018, 2:57 AM
Sonic
Sonic - avatar
+ 3
first -> you have to include stdlib.h // atoi second -> the type of binstr variable should be of type " char** " ( the atoi function take parameter of type "char* const" ): https://code.sololearn.com/c3HonWjfpj8M/#c atoi ref: https://en.cppreference.com/w/c/string/byte/atoi
4th Dec 2018, 1:04 AM
MO ELomari
MO ELomari - avatar
+ 1
I think for using strlen you should include the header file string.h
4th Dec 2018, 2:45 AM
Gaurav Maheshwari
Gaurav Maheshwari - avatar
+ 1
You're getting the correct amswer,i guess
4th Dec 2018, 2:56 AM
Gaurav Maheshwari
Gaurav Maheshwari - avatar