+ 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; }
6 Respostas
+ 7
Thanks Bennett Post and Mohamed ELomari .
+ 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?
+ 4
Yes!
+ 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
+ 1
I think for using strlen you should include the header file string.h
+ 1
You're getting the correct amswer,i guess