int  sscanf ( char * buffer, const char * format [ , argument , ...] );

Read formatted data from string.
  Reads data from the buffer specified and stores it into the locations given by argument(s). Locations pointed by each argument are filled with their corresponding type of value requested in the format string.
  There must be the same number of type specifiers in format string than arguments passed.


Buffer containing the string to be parsed for data.
String that can contain one or more of these items:
pointer to objects or structures to be filled with data read as specified by format string. There must be the same number of these parameters than the number of format tags. NOTE: These arguments must be pointers: if you want to store the result of a scanf operation on a standard variable you should precede it with the reference operator, i.e. an ampersand sign (&), like in:
int n;
sscanf (buffer,"%d",&n);

Return Value.
  The number of items succesfully read. This count doesn't include any ignored fields.
  If EOF is returned an error has occurred before the first assignation could be done.

  Defined in ANSI-C.


/* sscanf example */
#include <stdio.h>

main ()
  char sentence []="Benny is 29 years old";
  char str [20];
  int i;

  sscanf (sentence,"%s %*s %d",str,&i);
  printf ("%s -> %d\n",str,i);
  return 0;
Benny -> 29

See also.
  fscanf, printf,

© The C++ Resources Network, 2000