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 Student structure into a string?ComputerScienceOne · To String Functions
- How can you convert a string to a number using sscanf()?ComputerScienceOne · Conversions
- How does scanf() read integer, character, and floating-point input in C?ComputerScienceOne · Basic I/O
- How do fprintf() and fscanf() read from and write to plaintext files?ComputerScienceOne · Plaintext Files
- How can you create static strings with character arrays?ComputerScienceOne · Character Arrays
- How do pointers pass values by reference in C?ComputerScienceOne · Function Pointers
- How can strlen determine the length of a C string?ComputerScienceOne · String Library
- How can you create an array of strings in C?ComputerScienceOne · Arrays of Strings