printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换函数
参考: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个函数而言的。
printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换函数的更多相关文章
- printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换
总览 (SYNOPSIS) #include <stdio.h> int printf(const char *format, ...); int fprintf(FILE *stream ...
- printf()、sprintf()、vprintf()、vsprintf()(转)
转自http://sumsung753.blog.163.com/blog/static/14636450120112151092934/ 一.printf() printf()函数优点在于可以格式化 ...
- [misc]printf/fprintf/sprintf/snprintf函数
转自:http://blog.csdn.net/To_Be_IT_1/article/details/32179549 需要包含的头文件 #include <stdio.h> int pr ...
- 实例-sprintf() 函数详解-输出格式转换函数
Part1:实例 $filterfile = basename(PHP_SELF, '.php'); if (isset($_GET['uselastfilter']) && isse ...
- [ Skill ] print println printf fprintf sprintf lsprintf
https://www.cnblogs.com/yeungchie/ 几种 print 函数的差异 print 接收任意的数据类型,并打印到 CIW print( 12345 ) ; 12345 pr ...
- printf、sprintf与fprintf 的用法区分
原文链接 1: fprintf()#include <stdio.h> int fprintf( FILE *stream, const char *format, ... );fprin ...
- sprintf,snprintf的用法(可以作为linux中itoa函数的补充)【转】
转自:http://blog.csdn.net/educast/article/details/25068445 函数功能:把格式化的数据写入某个字符串 头文件:stdio.h 函数原型:int sp ...
- PHP中的输出:echo、print、printf、sprintf、print_r和var_dump
大家在面试中,经常会被问到的问题: 请简要说明PHP的打印方式都有哪些? 或者直接点问: 请说明echo.print.print_r的区别 看着很简单,一般会出现在初中级的笔试题中.但是要真正说明白这 ...
- php输出echo、print、print_r、printf、sprintf、var_dump的区别比较
本篇文章是对php输出echo.print.print_r.printf.sprintf.var_dump的区别进行了详细的分析介绍,需要的朋友参考下 用.net开发已经5年了,最近突然想接触 ...
随机推荐
- js刷新页面方法
1,reload 方法,该方法强迫浏览器刷新当前页面.语法:location.reload([bForceGet]) 参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取 ...
- bzoj 1324 Exca王者之剑(黑白染色,最小割)
[题意] 两相邻点不能同时选,选一个点集使得权值和最大. 出题人语文好... [思路] 将图进行黑白二染色,然后构建最小割模型. [代码] #include<set> #include&l ...
- 暴雪hash算法
你有一个非常大的字符串数组A,现在又有一个字符串B,需要你去检测B是否存在于A中.最简单粗暴的方法是遍历整个A,但是这个方法投入到实际应用时的运行速度是难以接受的.在没有与其他所有字符串比较前怎么知道 ...
- <Stackoverflow> 声望和节制
什么是声望(reputation)?我是怎样获得(或失去)它的? 声望是一种粗略的测量,用来表示社区对你的信任度.通过让别人相信你知道自己正在讨论什么来获得.对网站的基本使用,包括问一个问题,回答,建 ...
- anaconda在linux下的安装注意事项
不应该做什么 官网原文: Installation Instructions Linux Install These instructions explain how to install Anaco ...
- mvn deploy 报错:Return code is: 400, ReasonPhrase: Bad Request. ->
mvn deploy 报错:Return code is: 400, ReasonPhrase: Bad Request. -> TEST通过没有报错,但是最终部署到Nexus中时出现错误. 后 ...
- 第二百八十六天 how can I 坚持
bug不断啊,头疼. 今天早上到的倒是挺早. 中午吃的黄焖鸡,晚上加了会班. 勇江的鱼都死了,杨建的还剩3条,晚上到家都快十点了,还洗了衣服,没捞出来呢, 希望可以请下来假吧. 晾上衣服睡觉.
- HDU 5752 Sqrt Bo (数论)
Sqrt Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 Description Let's define the function f ...
- OOP 6大基本原则
1.开闭原则: 对扩展开发.对修改关闭. 2.里氏替换原则:子类替换父类(可以用父类对象的任何地方都可以用子类对象代替) 3.依赖倒置原则:程序要依赖于抽象接口,不要依赖于具体实现.简单的说就是要求对 ...
- 如何彻底隐藏iOS7应用的status bar
用xcode5开发新的iOS游戏,发现一个坑爹的现象,虽然我已经在info.plist里面把Status bar is initially hidden设置成了YES,但在设备上一跑还是看到丑陋的st ...