sscanf
int  sscanf ( char * buffer, const char * format [ , argument , ...] );
stdio.h
  cplusplus.com  

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.

Parameters.

buffer
Buffer containing the string to be parsed for data.
format
String that can contain one or more of these items:
argument(s)
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.

Portability.
  Defined in ANSI-C.

Example.

/* 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;
}
Output:
Benny -> 29

See also.
  fscanf, printf,


© The C++ Resources Network, 2000