sprintf function : sends formatted output to String
Sprintf function : sends formatted output to String
Features :
- Output is Written into String instead of Displaying it on the Output Devices .
- Return value is integer ( i.e Number of characters actually placed in array / length of string )
- String is terminated by ‘\0′
- Main Per pose : Sending Formatted output to String
- Header File : Stdio.h
Syntax :
int sprintf(char *buf,char format,arg_list);
Live Example :
int age = 23 ; char str[100]; sprintf( str , "My age is %d",age); puts(str);
Output of Above Program :
My age is 23
Analysis of Source Code : - Just keep in mind that
- Assume that we are using printf then we get output “My age is 23″
- What does printf does ? —- Just Print the Result on the Screen
- Similarly Sprintf stores result “My age is 23″ into string str instead of printing it.