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
- How does scanf() read integer, character, and floating-point input in C?ComputerScienceOne · Basic I/O
- How do argc and argv provide and convert command-line arguments?ComputerScienceOne · The cmain() Function
- How do fprintf() and fscanf() read from and write to plaintext files?ComputerScienceOne · Plaintext Files
- How do you read numeric input from a user in Java with Scanner?ComputerScienceOne · Converting Units
- Why is scanf() considered a risky input mechanism?ComputerScienceOne · Converting Units
- How can you create static strings with character arrays?ComputerScienceOne · Character Arrays
- How can strtok() split a string into tokens?ComputerScienceOne · Tokenizing