本文介绍了啜饮二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 1 0001000000000000001 2 0001000000000000001 3 10000011001000000000000001 4 10000011001000000000000001 5 10000011001000000000000001 6 10000011001000000000000001 7 10000011001000000000000001 8 10000011001000000000000001 9 10000011001000000000000001 10 10000011001000000000000001 1100000001111100 1200000001111100 13 100000001111100 14 1000001110110111100000000000001 15 1000001110110111100000000000001 16 1000001110110111100000000000001 17 1000001110110111100000000000001 18 1000001110110111100000000000001 19 1000001110110111100000000000001 20 0001000000000000001 1 2 ***** ***** ***** ***** ***** ***** ***** ***** 10 ************ 11 ************ ************ **** * *** 14 ***** *** ***** *** ***** *** ***** *** ***** *** 20 3W,12 B,5W 1000 0000111 1100 如果我想吸入上述20行没有行号,空格, 回车,换行或任何非零,一或EOF的东西, 我该怎么做? 提前致谢, - 乔治 恐怖袭击可以动摇我们的基础最大的建筑,但是他们无法触及美国的基础。这些行为粉碎了钢铁,但是他们无法削弱美国人的决心。 George W. Bush 图片日 http://apod.nasa.gov/apod/ 解决方案 假设你的意思是开头的二十行。将fgets() 后跟 int line_num; char数据[32]; fscanf(line,"%d%32s"& line_num,data); 做这个工作? - Nick Keighley 假设你的意思是开头的二十行。将fgets() 后跟 int line_num; char数据[32]; fscanf(行,%d%32s,& line_num,数据); 做这个工作? 为什么在scanf之前的fgets? 更好的数据集是: 1 0001000000000000001 2 0001000000000000001 3 10000011001000000000000001 4 10000011001000000000000001 5 10000011001000000000000001 6 10000011001000000000000001 7 10000011001000000000000001 8 10000011001000000000000001 9 10000011001000000000000001 10 10000011001000000000000001 11 100000001111100000000000001 1200000001111100000000000001 13 100000001111100000000000001 14 1000001110110111100000000000001 15 1000001110110111100000000000001 16 1000001110110111100000000000001 17 1000001110110111100000000000001 18 1000001110110111100000000000001 19 1000001110110111100000000000001 20 0001000000000000001 - 乔治 这场冲突的过程尚不清楚,但其结果是肯定的。 自由和恐惧,正义和残忍,一直处于战争状态,我们知道上帝是b $ b他们之间没有中立。 George W. Bush 每日图片 http://apod.nasa.gov/apod/ 3W,12 B,5W 1000 0000111 1100 假设你的意思是开头的二十行。将fgets() 后跟 int line_num; char数据[32]; fscanf(line,"%d%32s"& line_num,data); 做这个工作? 但是他会fgets()后跟fscanf(),这不是一次只吸一行同一行所有20行吗?这就是我所说的b $ b的意思。顺便说一下,我使用了sscanf()而不是fscanf()。 [cdalten @ localhost oakland] 1 00010000000000000012 00010000000000000013 100000110010000000000000014 100000110010000000000000015 100000110010000000000000016 100000110010000000000000017 100000110010000000000000018 100000110010000000000000019 1000001100100000000000000110 1000001100100000000000000111 10000000111110012 10000000111110013 10000000111110014 100000111011011110000000000000115 100000111011011110000000000000116 100000111011011110000000000000117 100000111011011110000000000000118 100000111011011110000000000000119 100000111011011110000000000000120 000100000000000000112**************************************** 10************ 11***************************** *** 14***** ******** ******** ******** ******** ***203W, 12 B, 5W1000 0000111 1100If I wanted to suck in the above 20 lines without line numbers, spaces,carriage returns, line feeds, or anything that is not a zero, one or EOF,how would I do it?Thanks in advance,--GeorgeTerrorist attacks can shake the foundations of our biggest buildings, butthey cannot touch the foundation of America. These acts shatter steel, butthey cannot dent the steel of American resolve.George W. BushPicture of the Day http://apod.nasa.gov/apod/ 解决方案assuming you mean the twenty lines at the beginning. Would fgets()followed byint line_num;char data[32];fscanf (line, "%d %32s", &line_num, data);do the job?--Nick Keighleyassuming you mean the twenty lines at the beginning. Would fgets()followed by int line_num; char data[32]; fscanf (line, "%d %32s", &line_num, data);do the job?Why fgets before scanf?The better data set is:1 00010000000000000012 00010000000000000013 100000110010000000000000014 100000110010000000000000015 100000110010000000000000016 100000110010000000000000017 100000110010000000000000018 100000110010000000000000019 1000001100100000000000000110 1000001100100000000000000111 10000000111110000000000000112 10000000111110000000000000113 10000000111110000000000000114 100000111011011110000000000000115 100000111011011110000000000000116 100000111011011110000000000000117 100000111011011110000000000000118 100000111011011110000000000000119 100000111011011110000000000000120 0001000000000000001--GeorgeThe course of this conflict is not known, yet its outcome is certain.Freedom and fear, justice and cruelty, have always been at war, and we knowthat God is not neutral between them.George W. BushPicture of the Day http://apod.nasa.gov/apod/assuming you mean the twenty lines at the beginning. Would fgets()followed by int line_num; char data[32]; fscanf (line, "%d %32s", &line_num, data);do the job?But he would would fgets() followed by fscanf(), wouldn''t that justsuck in one line at a time vs all 20 lines at once? Here is what Imean. BTW, I used sscanf() and not fscanf().[cdalten@localhost oakland] 这篇关于啜饮二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!