[收藏]使用scanf输入double格式的数据问题

本文详细介绍了格式化输入函数中格式说明符的构成及其各部分的作用,包括百分号开头的格式说明符、可选的抑制赋值字符、宽度指定符、指针大小修饰符等,并解释了如何使用这些组件来正确读取不同类型的变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

正确格式为%lf,scanf("%lf",double type variable);

原文地址:http://www.programfan.com/club/showpost.asp?id=22045&t=o

┌────────────────────────────────────────┐
│  ...scanf Format Specifiers                                                    │
├────────────────────────────────────────┤
│In ...scanf format strings, format specifiers have the following form:          │
│                                                                                │
│  % [ * ] [width] [F|N] [h|l|L] pe_char                                         │
│                                                                                │
│Each format specifier begins with the percent character (%).                    │
│                                                                                │
│After the % come the following, in this order:                                  │
│                                                                                │
│┌─────┬────────────────────────────────┐│
││Component │What It Is/Does                                                 ││
│├─────┼────────────────────────────────┤│
││ [ * ]    │(Optional) Assignment-suppression character                     ││
││          │Suppresses assignment of the next input field.                  ││
││ [width]  │(Optional) Width specifier                                      ││
││          │Specifies maximum number of characters to read; fewer           ││
││          │characters might be read if the ...scanf function encounters    ││
││          │a whitespace or unconvertible character.                        ││
││ [F|N]    │(Optional) Pointer size modifier                                ││
││          │Overrides default size of address argument:                     ││
││          │  N = near pointer                                              ││
││          │  F = far pointer                                               ││
││ [h|l|L]  │(Optional) Argument-type modifier                               ││
││          │Overrides default type of address argument:                     ││
││          │  h = short int                                                 ││
││          │  l = long int, if type_char specifies integer conversion       ││
││          │  l = double, if type_char specifies floating-point conversion  ││
││          │  L = long double, (valid only with floating-point conversion)  ││
││ type_char│(Required) Type character                                       ││
│└─────┴────────────────────────────────┘│
└────────────────────────────────────────┘

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值