Use C sscanf function to read data from a string

Syntax

C sscanf function has the following syntax.

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

C sscanf function is from header file stdio.h.

Description

C sscanf function is identical to scanf() except that data is from *buf.

C sscanf function returns the number of variables assigned. A value of zero means that no fields were assigned. EOF indicates an error.

Example

Use C sscanf function to read data from a string.


#include <stdio.h>
//  ww w .j  a v  a 2 s .com
int main(void)
{
  char str[80];
  int i;

  sscanf("hello 1 2 3 4 5", "%s%d", str, &i);
  printf("%s %d", str, i);

  return 0;
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h