Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言sprintf()函数:格式化输出到字符串中

C语言sprintf()函数:格式化输出到字符串中

点击打开在线编译器,边学边练

函数名: sprintf

头文件:<stdio.h>

函数原型: int sprintf(char *str, char *farmat [,argument,...]);

功 能: 格式化输出到字符串中

参数: char *str  要输出的字符串

           char *farmat [,argument,...]   要输入的格式

返回值: 返回字符串的字节数


程序例: 格式化输出到字符串中,并输出字符串

#include<stdio.h>

#include<math.h>

int main(void){

   char buffer[80];

   sprintf(buffer, "An approximation of Pi is %f", M_PI);

   puts(buffer);

   return 0;

}

 

运行结果

An approximation of Pi is 3.141593



本文固定URL:https://www.dotcpp.com/course/539

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)