2011-02-24 wcdj
%[*]type,此问题对scanf和fscanf通用。关于*号用法的解释如下。
%[*][width][modifiers]type
* —— An optional starting asterisk indicates that the data is to be retrieved from stdin but ignored, i.e. it is not stored in the corresponding argument.
应用场景1:
将文件中的数据读入到指定的变量中,文件中数据的格式为:(每行第一个数为行号,后三个数为int型,再后三个数为double型)
1 1,2,3,1.2,3.4,5.5
2 22,31,100,1.0,2.2,-3.5
……
结论:使用%*d可以跳过第一列的序号。
应用场景2:
从文件中逐个读出能读的浮点数,比如"1.0,3.5,2.2 ……"
题目来源:
http://topic.csdn.net/u/20110218/12/E039E736-CA2F-4168-B06A-14D386D511C5.html
http://topic.csdn.net/u/20110223/15/3fd75e15-fe7d-432b-8b6c-c048ddec20a0.html?38465
测试数据:
1 1,2,3,1.2,3.4,5.5
2 22,31,100,1.0,2.2,-3.5
wcdj 2011 hello123.456world #123&456*789!
输出:
[1]==1
[2]==1
[3]==2
[4]==3
[5]==1.2
[6]==3.4
[7]==5.5
[8]==2
[9]==22
[10]==31
[11]==100
[12]==1
[13]==2.2
[14]==-3.5
[15]==2011
[16]==123.456
[17]==123
[18]==456
[19]==789