|
|
coherent
sscanf() STDIO sscanf()
Format a string
#include <stdio.h>
iinntt ssssccaannff(_s_t_r_i_n_g, _f_o_r_m_a_t [, _a_r_g ] ...)
cchhaarr *_s_t_r_i_n_g; cchhaarr *_f_o_r_m_a_t;
sscanf reads the argument string, and uses format to specify a
format for each arg, each of which must be a pointer. For more
information on sscanf's conversion codes, see scanf.
***** Example *****
This example uses sspprriinnttff to create a string, and then reads it
with ssssccaannff. It also illustrates a common problem with this
routine.
#include <stdio.h>
main()
{
char string[80];
char s1[10], s2[10];
sprintf(string, "123456789012345678901234567890");
sscanf(string, "%9c", s1);
sscanf(string, "%10c", s2);
printf("\n%s is the string\n", string);
printf("%s: first 9 characters in string\n", s1);
printf("%s: first 19 characters in string\n", s2);
}
***** See Also *****
fscanf(), scanf(), STDIO
***** Diagnostics *****
sscanf returns the number of arguments filled. It returns zero
if no arguments can be filled or if an error occurs.
***** Notes *****
Because C does not perform type checking, an argument must match
its format specification. sscanf is best used only to process
data that you are certain are in the correct data format, such as
data that were written with sprintf.
COHERENT Lexicon Page 1
sscanf() STDIO sscanf()
sscanf is difficult to use correctly, and incorrect usage can
create serious bugs in programs. It is recommended that strtok
be used instead.
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.