关于printf系列函数
2011-03-08 19:05
169 查看
#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>
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);
he functions in the printf() family produce output according to a format as described below. The functions printf() and vprintf() write output to stdout, the standard output stream; fprintf() and vfprintf() write output to the given output stream; sprintf(), snprintf(),vsprintf() and vsnprintf() write to the character string str.
The functions vprintf(), vfprintf(), vsprintf(), vsnprintf() are equivalent to the functions printf(), fprintf(), sprintf(), snprintf(), respectively, except that they are called with a va_list instead of a variable number of arguments. These functions do not call the va_end macro. Consequently, the value of ap is undefined after the call. The application should call va_end(ap) itself afterwards.
In ISO C99,
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>
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);
he functions in the printf() family produce output according to a format as described below. The functions printf() and vprintf() write output to stdout, the standard output stream; fprintf() and vfprintf() write output to the given output stream; sprintf(), snprintf(),vsprintf() and vsnprintf() write to the character string str.
The functions vprintf(), vfprintf(), vsprintf(), vsnprintf() are equivalent to the functions printf(), fprintf(), sprintf(), snprintf(), respectively, except that they are called with a va_list instead of a variable number of arguments. These functions do not call the va_end macro. Consequently, the value of ap is undefined after the call. The application should call va_end(ap) itself afterwards.
In ISO C99,
snprintfwas introduced as an alternative to
sprintfthat can help avoid the risk of a buffer overflow:
int snprintf(char *str, size_t size, const char * restrict format, ...)
snprintfis guaranteed not to write more than size bytes into str, so use of it can help avoid the risk of a buffer overflow, as in the following code fragment:
相关文章推荐
- 关于printf系列格式化输出函数,%S格式的分析
- printf系列函数关于输出字符串“%n”
- 关于语音聊天(wave系列函数播放文件、网络音频)的实现方法
- 关于i2c_smbus系列函数
- 关于getpw系列函数返回的静态区域
- 关于Scanf和Printf函数的一些知识点
- C 中 关于printf 函数中度剖析
- php中关于socket的系列函数总结
- 关于printf函数的返回值问题
- 【C语言】关于printf函数输出字符格式
- 关于printf函数的思考
- va_list、va_start、va_end(用于实现函数参数的个数可变的函数,如scanf()/printf()系列函数)
- 关于printf函数的讨论
- 关于C语言中printf函数的一个问题
- 关于printf函数的小练习
- 关于sprintf的系列函数(转自CSDN)
- win32 下 支持浮点的printf系列函数
- 关于printf函数输出先后顺序的讲解!!
- 关于printf()函数和浮点数
- [C++系列] Printf系列函数的玄机