您的位置:首页 > 其它

scanf/fscanf/sscanf、vscanf/vfscanf/vsscanf

2016-02-21 22:09 471 查看

scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf - input format conversion

格式化输入

#include <stdio.h>

int scanf(const char *format, ...);
int fscanf(FILE *stream, const char *format, ...);
int sscanf(const char *str, const char *format, ...);
//Return: number of input items assigned,
//        EOF if input error or end of file before any conversion


scanf
用于标准输入

fscanf
用于指定的流

sscanf
用于指定的字符串

vscanf等

将scanf系列中的参数(…)换成了
va_list


#include <stdarg.h>

int vscanf(const char *format, va_list ap);
int vsscanf(const char *str, const char *format, va_list ap);
int vfscanf(FILE *stream, const char *format, va_list ap);
//Return: number of input items assigned,
//        EOF if input error or end of file before any conversion


format:scanf指定的参数

转换规范中有三个可选的组件,显示在下面的括号中:

There are three optional components to a conversion specification, shown in square brackets below:

%[∗][fldwidth][m][lenmodifier]convtype\%[*][fldwidth][m][lenmodifier]convtype

* The optional leading asterisk(*) is used to
suppress(压制)
conversion. Input is converted as specified by the rest of the conversion specification, but the result is not stored in an argument.

fldwidth
The fldwidth component specifies the maximum field width in characters.



因为标准IO库的内容会在之后讲解C的教程中详细讲解,这里也不多讲,日后补充
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: