int sprintf(char *buffer,const char *format[,argument...]);
结合函数原型,sprintf() 函数的功能是将 format 指向的格式化数据输出到 buffer 指向的数组中。
- #include <stdio.h>
- int main() {
- int age = 30;
- double salary = 50000.50;
- char name[] = "Alice";
- char output[100];
- sprintf(output, "Name: %s, Age: %d, Salary: %.2f", name, age, salary);
- printf("%s\n", output); // 输出:Name: Alice, Age: 30, Salary: 50000.50
- return 0;
- }
https://c.biancheng.net/c/sprintf.html