

sscanf()                      STDIO                      sscanf()




Format a string

#include <stdio.h>
iinntt ssssccaannff(_s_t_r_i_n_g, _f_o_r_m_a_t [, _a_r_g ] ...)
cchhaarr *_s_t_r_i_n_g; cchhaarr *_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 sspprriinnttff to create a string,  and then reads it
with  ssssccaannff.  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


