sscanf() function:c program
This function is same as scanf() function but it reads from string rather than standard input.
/*Program to illustrate the use of sscanf() function*/
#include
int main()
{
//declare two strings
char s1[20]="1234";
char s2[20]="345.67";
//declare int and float variables
int n;
float f;
//convert the variables into string
sscanf(s1,"%d",&n);
sscanf(s2,"%f",&f);
//print the converted strings
printf("Value of n=%d\nValue of f=%f\n",s1,s2);
}
0 comments: