Need help in reading .txt file which contains a table with blanks?
Consider this -
"ID_REF" "GSM887" "GSM888" "GSM889" "GSM890" "GSM891"
10 -.427 -3.841 .312 0 11 -.939 -1 &开发者_运维知识库nbsp; -.024Now how to recognize blanks when I am traversing through whole text file containing many such entries. I need to find mean of every column so how do I skip blank (null) values. It will be helpful if someone can tell me a way to do it in C++.
if the only delemiter is an arbitrary number of spaces, then you can't, because then
"ID_REF" "GSM887" "GSM888" "GSM889" "GSM890" "GSM891"
11 -.939 -1 -.024
is the same as
"ID_REF" "GSM887" "GSM888" "GSM889" "GSM890" "GSM891"
11 -.939 -1 -.024
check the character codes and hopefully you have /t or whatever a tab character is in there instead of just all spaces.
Ah, since you have tabs, your data actually looks like this
"ID_REF" "GSM887" "GSM888" "GSM889" "GSM890" "GSM891"
11 \t -.939 \t -1 \t -.024 \t \t
What you need to do now is called parsing a delimted string to an array. Something like this C: creating array of strings from delimited source string
or even better, what rubber boots said
I agree with @Matt. You can replace all the spaces with comma in txt (switch it to a csv file in excel) and you will be good to go.
精彩评论