[参考]C的scanf 和 C++的fscanf 的用法
| 格式字符 | 说明 |
| %a、%A | 读入一个浮点值(仅C99有效) |
|
%f 、 %F、%e、
%E、%g 、%G
|
读入一个浮点数
|
| %c、%C | 读入一个字符 |
| %d | 读入十进制整数 |
| %s | 读入一个字符串 |
| %p | 读入一个指针 |
| %u |
读入一个无符号十进制整数
|
| %n | 至此已读入值的等价字符数 |
| %[] | 扫描字符集合 |
| %% | 读%符号 |
| %o | 读入八进制整数 |
| %x 、%X | 读入十六进制整数 |
| %i | 读入十进制,八进制,十六进制整数 |
| sub-specifier | description |
|---|---|
| * | An optional starting asterisk indicates that the data is to be read from the stream but ignored (i.e. it is not stored in the location pointed by an argument). 注:加上*可将该位置数据忽略 |
| width | Specifies the maximum number of characters to be read in the current reading operation (optional). 注:比如填入7.3,表示整数部分宽度为7,小数部分只读到第3位;也可以不填,不填则将对应数据不带舍入地读入 |
| length | One of hh, h, l, ll, j, z, t, L (optional). This alters the expected type of the storage pointed by the corresponding argument (see the last table). |
Where the specifier character at the end is the most significant component, since it defines which characters are extracted, their interpretation and the type of its corresponding argument:
| specifier | Description | Characters extracted |
|---|---|---|
| i, u | Integer | Any number of digits, optionally preceded by a sign (+ or -). Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and 0x hexadecimal digits (0-f). |
| d | Decimal integer (十进制数) |
Any number of decimal digits (0-9), optionally preceded by a sign (+ or -). |
| o | Octal integer | Any number of octal digits (0-7), optionally preceded by a sign (+ or -). |
| x | Hexadecimal integer (16进制数) | Any number of hexadecimal digits (0-9, a-f, A-F), optionally preceded by 0x or 0X, and all optionally preceded by a sign (+ or -). |
| f, e, g | Floating point number (浮点数) |
A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod). Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X. |
| a | ||
| c | Character | The next character. If a width other than 1 is specified, the function reads exactlywidth characters and stores them in the successive locations of the array passed as argument. No null character is appended at the end. |
| s | String of characters | Any number of non-whitespace characters, stopping at the first whitespacecharacter found. A terminating null character is automatically added at the end of the stored sequence. |
| p | Pointer address | A sequence of characters representing a pointer. The particular format used depends on the system and library implementation, but it is the same as the one used to format %p in fprintf. |
| [characters] | Scanset | Any number of the characters specified between the brackets. A dash (-) that is not the first character may produce non-portable behavior in some library implementations. |
| [^characters] | Negated scanset | Any number of characters none of them specified as characters between the brackets. |
| n | Count | No input is consumed. The number of characters read so far from stream is stored in the pointed location. |
| % | % | A % followed by another % matches a single %. |
Except for n, at least one character shall be consumed by any specifier. Otherwise the match fails, and the scan ends there.
| specifiers | |||||||
|---|---|---|---|---|---|---|---|
| length | d i | u o x | f e g a | c s [] [^] | p | n | |
| (none) | int* | unsigned int* | float* | char* | void** | int* | |
| hh | signed char* | unsigned char* | signed char* | ||||
| h | short int* | unsigned short int* | short int* | ||||
| l | long int* | unsigned long int* | double* | wchar_t* | long int* | ||
| ll | long long int* | unsigned long long int* | long long int* | ||||
| j | intmax_t* | uintmax_t* | intmax_t* | ||||
| z | size_t* | size_t* | size_t* | ||||
| t | ptrdiff_t* | ptrdiff_t* | ptrdiff_t* | ||||
| L | long double* | ||||||
Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99.
[参考]C的scanf 和 C++的fscanf 的用法的更多相关文章
- scanf/sscanf %[]格式控制串的用法(转)
scanf/sscanf %[]格式控制串的用法 scanf中一种很少见但很有用的转换字符:[...]和[ ^...]. #include<stdio.h> int main() { ch ...
- sprintf()、fprintf()、fscanf()的用法
sprintf函数的用法1.该函数包含在stdio.h的头文件中. 2.sprintf和平时我们常用的printf函数的功能很相似.sprintf函数打印到字符串中,而printf函数打印输出到屏幕上 ...
- fscanf的用法
fscanf用于读取字符串数据流,遇到空白字符(空格' '; 制表符'\t'; 新行符'\n')就停止,若要读取完整的一行数据,可以使用格式控制("%[^\n]%*c"),或者使用 ...
- 关于while (~scanf("%d %d", &m, &n))的用法
其功能是循环从输入流读入m和n,直到遇到EOF,有如下关系: while (~scanf("%d %d", &m, &n)) ↔ while (scanf(&quo ...
- scanf,fscanf,sscanf的区别
scanf是从文件中读 sscanf是从字符串中读 scanf是从键盘输入中读 fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.fscanf :格式 ...
- scanf,fscanf,sscanf的区别----整理
转自原文 scanf,fscanf,sscanf的区别----整理 scanf 从控制台输入 fscanf 从文件输入 sscanf 从指定字符串输入 1.例:使用scanf函数输入数据. #incl ...
- 进程操作篇atexit execl exit fprintf fscanf getpid nice get priority printf setpid system vfork wait waitpid
atexit(设置程序正常结束前调用的函数) 相关函数 _exit,exit,on_exit 表头文件 #include<stdlib.h> 定义函数 int atexit (void ( ...
- matlab fscanf用法
matlab fscanf用法 matlab中的fscanf的用法如下: A=fscanf(fid,format)[A, count]=fscanf(fid,format,size) [A, coun ...
- fscanf函数的用法
fscanf函数用法 简要介绍 fscanf()函数是格式化读写函数.它读取的对象是磁盘文件 函数原型: int fscanf(FILE * fp,char * format,...); 其中fp为文 ...
随机推荐
- centos7通过阿里云配置docker加速镜像
针对Docker客户端版本大于1.10.0的用户 您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器: sudo mkdir -p /etc/docker s ...
- 使用渐进式 JPEG 来提升用户体验
原文出处: 标点符 今天才认识到原来JPEG文件有两种保存方式,分别是Baseline JPEG(标准型)和Progressive JPEG(渐进式).两种格式有相同尺寸以及图像数据,扩展名也是相 ...
- Git 使用vi或vim
1.vi & vim 有两种工作模式: (1) 命令模式:接受.执行 vi & vim 操作命令的模式,打开文件后的默认模式: (2) 编辑模式:对打开的文件内容进行 增.删.改 操作 ...
- 入木三分学网络第一篇--VRRP协议详解第一篇(转)
因为keepalived使用了VRRP协议,所有有必要熟悉一下. 虚拟路由冗余协议(Virtual Router Redundancy Protocol,简称VRRP)是解决局域网中配置静态网关时,静 ...
- Linux下的内核抢占
2017-03-03 很遗憾之前在介绍进程调度的文章中,虽然涉及到了内核抢占,但是却没有对其进行深入介绍,今天就稍微总结下内核抢占. 内核抢占在一定程度上减少了对某种事件的响应延迟,这也是内核抢占被引 ...
- 华为交换机VRP用户界面配置及Telnet登录实验
user privilege level level 设置使用以上用户界面登录后的用户级别 5 acl acl-number { inbound | outbound } (可选)在用户界面上应用AC ...
- 011-Shell 文件包含
和其他语言一样,Shell 也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件. Shell 文件包含的语法格式如下: . filename # 注意点号(.)和文件名中间有一空 ...
- CheckStyle——检查编码格式等是否符合规范
CheckStyle 一.checkstyle简介 checkstyle是idea中的一个插件,可以很方便的帮我们检查java代码中的格式错误,它能够自动化代码规范检查过程,从而使得开发人员从这项重要 ...
- Flask系列(十)自定义Form组件
一.wtforms源码流程 1.实例化流程分析 # 源码流程 1. 执行type的 __call__ 方法,读取字段到静态字段 cls._unbound_fields 中: meta类读取到cls._ ...
- python学习笔记(十六)内置函数zip、map、filter的使用
1.zip,就是把两个或者多个list,合并到一起,如果想同时循环2个list的时候,就使用zip.示例如下: l1 = ['a','b','c','e','f','g'] l2 = [,,] l3= ...