COHERENT manpages

This page displays the COHERENT manpage for sscanf() [Format a string].

List of available manpages
Index


sscanf() -- STDIO Function (libc)

Format a string
#include <stdio.h>
int sscanf(string, format [, arg ] ...)
char *string; char *format;

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 sprintf()  to create  a string, and  then reads  it with
sscanf().  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(),
libc,
scanf()
ANSI Standard, §7.9.6.6
POSIX Standard, §8.1

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().

sscanf()  is difficult  to use  correctly, and  incorrect usage  can create
serious bugs in programs.  It is recommended that you use strtok() instead.