参考:http://blog.sina.com.cn/s/blog_674b5aae0100prv3.html

总览 (SYNOPSIS)

#include <stdio.h>

int printf(const char *format, ...);

int fprintf(FILE *stream, const char *format, ...);

int sprintf(char *str, const char *format, ...);

int snprintf(char *str, size_t size, const char *format, ...);

#include <stdarg.h>------------现在好像都在stdio.h中进行声明。

int vprintf(const char *format, va_list ap);

int vfprintf(FILE *stream, const char *format, va_list ap);

int vsprintf(char *str, const char *format, va_list ap);

int vsnprintf(char *str, size_t size, const char *format, va_list ap);

描述 (DESCRIPTION)

print系列函数根据format 参数生成输出内容。

printf和vprintf函数把输出内容写到stdout,即标准输出流;

fprintf和vfprintf函数把输出内容写到给定的stream流;

sprintf、snprintf、 vsprintf和vsnprintf函数把输出内容存放到字符串str中.。

这些函数由格式字符串format参数控制输出内容,它指出怎么样把后面的参数(或通过stdarg(3)的变长参数机制访问的 参数)转换成输出内容。

这些函数返回打印的字符数量(不包括字符串结尾用的‘\0‘)。snprintf和vsnprintf的输出不会超过size 字节(包括了结尾的`\0'), 如果因为这个限制导致输出内容被截断, 则函数返回-1。(这句话解释有误,可以参考man手册,原文关于返回值表述如下:)

Return value
       Upon successful return, these functions return the number of characters
       printed  (not  including  the  trailing  ’\0’  used  to  end  output to
       strings).  The functions snprintf() and vsnprintf() do not  write  more
       than size bytes (including the trailing ’\0’). If the output was trun-
       cated due to this limit then the return value is the number of  charac-
       ters (not including the trailing ’\0’) which would have been written to
       the final string if enough space had been  available.  Thus,  a  return
       value  of  size  or more means that the output was truncated. (See also
       below under NOTES.)  If an output  error  is  encountered,  a  negative
       value is returned.

从手册中可以看出,意思是如果输出由于受到size的限制而被截断输出,返回值则是被截断后并写入str中的字符数(不包括‘\0’),并且前提是str有足够的可用空间。

而如果输出遇到错误,会返回一个负值。这句话是针对上面8个函数而言的。

最新文章

  1. xhtml、html与html5的区别
  2. 什么是Servlet?它有哪些特点
  3. iOS-自定义Log
  4. ARTICLES
  5. WPF——数据绑定(一)什么是数据绑定
  6. Struts2笔记——与ServletAPI解耦
  7. centos系统下安装使用composer教程
  8. 深入理解计算机系统第二版习题解答CSAPP 2.11
  9. IE下判断IE版本的语句
  10. Java面试题之Class.forName的作用
  11. QFrame好像是万能的(可以随意画线,或者图片,放在其它元素之间做点缀,还可OnClick)
  12. OJ提交题目中的语言选项里G++与C++的区别(转载)
  13. testNg的安装与卸载
  14. bzoj1298题解
  15. [HNOI2011]任务调度
  16. window下 多开redis
  17. js string类型时间转换成Date类型
  18. Git常用命令总结(超实用)【转】
  19. RuntimeException: Type &quot;nmethodBucket*&quot;, referenced in VMStructs::localHotSpotVMStructs in the remot
  20. HDU - 2043密码 水题

热门文章

  1. 常见设计模式解析和实现(C++)Prototype模式(原型模式)
  2. JDBC获取表的主键
  3. mybatis系列-13-resultMap总结
  4. Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
  5. restsharp发送服务端请求回传session
  6. 分类算法之朴素贝叶斯分类(Naive Bayesian Classification)
  7. java BigInteger类的用法
  8. 第二百九十八天 how can I 坚持
  9. WebService学习之三:spring+cxf整合
  10. Nginx应用案例分享:压力测试