Concept
How do sscanf() and sprintf() work with strings?
ComputerScienceOne / Tokenizing
"The sscanf() function differs in its first argument: the string that contains the value you want to parse. Otherwise, the second two arguments are as in scanf(): the format (as a string) and the variable(s) that the results should be stored in (passed by reference). Likewise, there is a companion sprintf() which is similar to the printf() function, but instead of printing to the standard output, it “prints” to the string. That is, the result is placed in a string.\n\nint x = 10;\n\ndouble y = 3.14;\n\nchar *s = (char *) malloc(sizeof(char) * 50);\n\nsprintf(s, \"The value of x is %d, y = %f.\", x, y);\n\n// s now contains \"The value of x is 10, y = 3.140000.\""
Related Ideas
- How can you convert a string to a number using sscanf()?ComputerScienceOne · Conversions
- Why is strtok() not reentrant, and what alternative does C provide?ComputerScienceOne · Tokenizing
- How can you tokenize a String in Java?ComputerScienceOne · Tokenizing
- How does PHP compare strings with case-sensitive and case-insensitive functions?ComputerScienceOne · Tokenizing
- How can PHP split strings into tokens using explode() and preg_split()?ComputerScienceOne · Tokenizing