Is it possible to convert char * to float using sscanf()? I tried this but it doesn't work.
Thanks.Code:#include <stdio.h> int main() { float number; char price[] = "49.99"; sscanf(price, "%lf", number); printf("%lf", number); return 0; }
Is it possible to convert char * to float using sscanf()? I tried this but it doesn't work.
Thanks.Code:#include <stdio.h> int main() { float number; char price[] = "49.99"; sscanf(price, "%lf", number); printf("%lf", number); return 0; }
sscanf(price, "%f", &number);
printf("%f", number);
and if you're interested:
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Or even add the compiler option
gcc -Wall
if you're using gcc/dev-c++/mingw/cygwin
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.