The sscanf( ) and sprintf( ) functions

The sscanf( ) AND sprintf( ) FUNCTIONS :

a) sscanf( ):
                   The sscanf( ) function allows to read character from a character array and writes them to another array.
                    This function is similar to scanf( ) but instead from standard input it's reads data from an array.

Example: 
#include<stdio.h>
#include<conio.h>
void main( )
{

char in[10],out[10];
gets(in);
sscanf(in,"%s",out);
printf("%s\n",out);
}
OUTPUT :
HELLO
HELLO

Explanation :
In the above program two character array in[10] and out[10] are declared.The gets( ) function read the string through the terminal and it is stored in the array in[ ].Till this time the out [ ] array is empty.The sscanf ( ) function reads character from array in[ ] and assignes it to array out[ ].Thus,both the array contain the same string.At the end of the printf( )function displays the contents of array out [ ].

b) The sprintf( ):
                          The sprintf ( ) function is similar to the printf ( ) function except a small difference between them.The printf( ) function sends the out put to the screen,where as sprintf( ) function write the values from any data of characters.The following program is illustrated pertaining to sprintf( ).

Example :
#include<stdio.h>
#include<conio.h>
void main( )
{
int a=10;
char c='C';
float p=3.14;
char spf[20];
sprintf("spf,"%d%c %.2f",a,c,p);
printf("\n%s",spf);
}
OUTPUT :
10  C  3.14

Explanation :
In the above program sprintf( ) stores the values of variables in the character array spf[ ].While sprintf ( ) function execute the contained variables won't be displayed on the screen.The contents of an array spf is displayed using printf( ) function.