scanf 的用法

scanf:read from stdin and stores them according to the parameter format into the locations pointed by the additional arguments.

whitespace character: scanf will ignore any whitespace(including blank space, newline, and tab characters) which are encountered before the next non-whitespace character;

format specifiers: 一个由百分号%起始的字符串表示一个format specifier, 用来明确从stdin读取的数据的类型。它的一般形式为: %[*][width][modifier]type

*:indicate that the data is to be retrieved from stdin but ignored;

width:specify the maximum number of characters to be read in the current reading operation.

modifier: specify a size different from int(d,i,n),unsigned int(o,u,x),float(e,f,g)

             h: short int(d,i,n) unsigned short(for o u x)

             l:long int( d ,i ,n ) unsigned long int(o u x) double(e f g)

             L: long double(e,f ,g)

type: a character used to specify the type of the  data to be read.

c:single character   

d: decimal integer

e E f g G: floating point

o: octal integer

s:string of characters(read subsequent characters until a whitespace is found)

u: unsigned decimal integer

x,X: hexadecimal integer


e.g.    scanf("%s",str);

          scanf("%d",&i);

          scanf("%d %d",&i,&j);  







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值