I've assigned a number into character pointer:
I want to convert pointer strNumSet into float. What is the correct way to do this?Code:char* strNumSet = "12.33";
Kindly thanks for any suggestion and help.
I've assigned a number into character pointer:
I want to convert pointer strNumSet into float. What is the correct way to do this?Code:char* strNumSet = "12.33";
Kindly thanks for any suggestion and help.
bit∙hub [bit-huhb] n. A source and destination for information.
strtofl():
The slight imprecision which might be observable here is due to the nature of floating point numbers.Code:#include <stdio.h> #include <stdlib.h> int main(int argc, const char *argv[]) { char s[] = "42.7"; float n = strtof(s,NULL); printf("%s %f\n",s,n); return 0; }
If you are using gcc, you must compile -std=c99. Otherwise, you can use "string to double", strtod().
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge