sprintf() in C
Syntax:
int sprintf(char *str, const char *string,...);
sprintf stands for “String print”. Instead of printing on console, it store output on char buffer which are specified in sprintf
Example:
// Example program to demonstrate sprintf() #include<stdio.h> int main() { char buffer[50]; int a = 10, b = 20, c; c = a + b; sprintf(buffer, "Sum of %d and %d is %d", a, b, c); // The string "sum of 10 and 20 is 30" is stored // into buffer instead of printing on stdout printf("%s", buffer); return 0; } |
chevron_right
filter_none
Output:
Sum of 10 and 20 is 30
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- What is the difference between printf, sprintf and fprintf?
- Maximum String Partition
- Convert an unbalanced bracket sequence to a balanced sequence
- asctime() and asctime_s() functions in C with Examples
- Minimum operations required to convert a binary string to all 0s or all 1s
- String Range Queries to find the number of subsets equal to a given String
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- Swap characters in a String
- Sort an array of strings according to string lengths using Map
- time.h header file in C with Examples
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Round the given number to nearest multiple of 10 | Set-2
- Java program to check whether a string is a Palindrome
- Program to parse the Molecules and get the Atoms count



