Right Click to Search

Friday, January 22, 2025

Sprintf function : sends formatted output to String


Sprintf function :  sends formatted output to String

Features :
  1. Output is Written into String instead of Displaying it on the Output Devices .
  2. Return value is integer ( i.e Number of characters actually placed in array / length of string )
  3. String is terminated by '\0'
  4. Main Per pose : Sending Formatted output to String
  5. 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.

Tags / Keywords : | , , ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates