C++ :: sscanf() function

C++ :: sscanf() function


    The sscanf() function in C++ Read formatted data from string.

    Syntax :
int sscanf ( const char * s, const char * format, ...);
   The sscanf() function Reads data from s and stores them according to parameter format into the locations given by the additional arguments, as if scanf was used, but reading from s instead of the standard input (stdin).
The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.
const char * s
C string that the function processes as its source to retrieve the data.
const char * format
C string that contains a format string that follows the same specifications as format in scanf 
...(additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the appropriate type.
There should be at least as many of these arguments as the number of values stored by the format specifiers. Additional arguments are ignored by the function.

On success, the function returns the number of items in the argument list successfully filled. This count can match the expected number of items or be less (even zero) in the case of a matching failure.
In the case of an input failure before any data could be successfully interpreted, EOF is returned.


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

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

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