sscanf()

Syntax
#include <stdio.h>

  
  int sscanf(const char *s, const char *format, ...);

  
Description

sscanf() scans string s according to the given format, storing the values in the given parameters. The format specifiers in the format tell sscanf() what to expect next. A format specifier has the format:

You can also use a scan set to read a character string that either contains only the given characters or contains only characters not in the set. A scan set always is bracketed by left and right brackets. If the first character in the set is ^, the set is inverted (that is, only characters not in the set are allowed). You can specify whole character ranges, (for example, A-Z specifies all upper-case letters). To include a right bracket in the scan set, it must be the first element in the list; a dash ( -) must be either the first or the last element. To include a ^ in the list (instead of indicating an inverted list) ensure that the ^ is not the first character after the left bracket.

Some examples are:

[A-Za-z] Allows all upper- and lower-case characters.

[^A-Z] Allows any character that is not an upper-case character.

[]abc] Allows ], a, b and c.

[^]abc] Allows any character except ], a, b and c.

[-abc] Allows -, a, b and c.

A white space in the format string skips all white space characters up to the next non-white-space character. Any other character in the format must be exactly matched by the input; otherwise sscanf() stops scanning.

The syntax for numbers as scanned by sscanf() is the following:

  Number = FloatNumber|IntNumber 
  
  IntNumber = DecNumber|OctNumber|HexNumber 
  
  DecNumber = SignDigit{Digit} 
  
  OctNumber = Sign0{OctDigit} 
  
  HexNumber = 0(x|X) HexDigit {HexDigit} 
  
  FloatNumber = Sign {Digit} [.{Digit}] [Exponent] 
  
  Exponent = (e|E)DecNumber 
  
  OctDigit = 0|1|2|3|4|5|6|7 
  
  Digit = OctDigit|8|9 
  
  HexDigit = Digit |A|B|C|D|E|F|a|b|c|d|e|f 
  
Return

EOF, if s is NULL; otherwise it returns the number of arguments filled in.

Note: If sscanf() finds an illegal input (that is, not matching the required syntax), it simply stops scanning and returns successfully.