C programming sscanf stdio.h

In C programming the <stdio.h> sscanf function allows reading of data from an array.The declaration of the function is given below.

int sscanf(const char * restrict s ,
const char * restrict format, …) ;

s -The array from which the data is read.

format -A string with conversion specifier

-A lists of variables to hold the data entered by the programmer.

Return type
int -Returns the value of the macro EOF if an input failure occurs before any conversion. Otherwise,the sscanf function returns the number of input items assigned,which can be fewer than provided for,or even zero,in the event of an early matching failure.

***Note ‘sscanf’ is equivalent to ‘fscanf’ except that sscanf read the data from an array rather than from a stream.

Link : C fscanf stdio.h

Code example

size_t ret , i1 ;

char str[]=”HappyNew 1223″ , ch[15];

ret=sscanf(str , “%s %d”, ch , &i1);

printf(“ret=%d”, ret );

printf(“\n%s \n%d” , ch , i1);

Output ,


The string read from ‘str’ is stored in ‘ch’ and the integer is stored in i1.

Related links

->C scanf stdio.h

->C vsscanf stdio.h