Concept
How can you convert a string to a number using sscanf()?
ComputerScienceOne / Conversions
"We’ve previously examined the functions atoi() and atof() that allow you to convert strings that hold numeric values to int and double values respectively. Another way to convert strings to numbers is to use a function similar to the familiar scanf() function which reads its string from the standard input. The sscanf() function reads its “input” from a string instead of the standard input.\n\nchar s[] = \"103212.3214\";\n\ndouble x;\n\nsscanf(s, \"%lf\", &x);\n\n//x now has the value"
Related Ideas
- How do sscanf() and sprintf() work with strings?ComputerScienceOne · Tokenizing
- Why is scanf() considered a risky input mechanism?ComputerScienceOne · Converting Units
- How can individual characters in a string be accessed safely?ComputerScienceOne · Basic Operations
- How can strings be created and assigned to variables?ComputerScienceOne · Basic Operations
- How can you compute a substring of a string?ComputerScienceOne · Arrays of Strings