.TH sscanf() "" "" "STDIO Function (libc)"
.PC "Format a string"
.B "#include <stdio.h>"
\fBint sscanf(\fIstring\^\fB, \fIformat \fR[\^\fB, \fIarg \fR] .\^.\^.\^\fB)\fR
\fBchar *\fIstring\^\fB; char *\fIformat\^\fB;\fR
.PP
.B sscanf()
reads the argument
.IR string ,
and uses
.I format
to specify a format for each
.IR arg ,
each of which must be a pointer.
For more information on
.BR sscanf() 's
conversion codes, see
.BR scanf() .
.SH Example
This example uses \fBsprintf()\fR to create a string, and then reads it
with \fBsscanf()\fR.
It also illustrates a common problem with this routine.
.DM
#include <stdio.h>
.sp \n(pDu
main()
{
	char string[80];
	char s1[10], s2[10];
.DE
.DM
	sprintf(string, "123456789012345678901234567890");
	sscanf(string, "%9c", s1);
	sscanf(string, "%10c", s2);
.DE
.DM
	printf("\en%s is the string\en", string);
	printf("%s: first 9 characters in string\en", s1);
	printf("%s: first 19 characters in string\en", s2);
}
.DE
.SH "See Also"
.Xr "fscanf()," fscanf
.Xr "libc," libc
.Xr "scanf()" scanf
.br
\*(AS, \(sc7.9.6.6
.br
\*(PX Standard, \(sc8.1
.SH Diagnostics
.B sscanf()
returns the number of arguments filled.
It returns zero if no arguments can be filled or if an error occurs.
.SH Notes
Because C does not perform type checking,
an argument must match its format specification.
.B 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
.BR sprintf() .
.PP
.B sscanf()
is difficult to use correctly, and incorrect usage can create serious
bugs in programs.
It is recommended that you use
.B strtok()
instead.
