2

Consider this -

"ID_REF" "GSM887" "GSM888" "GSM889" "GSM890" "GSM891"
10              -.427                          -3.841       .312 0
11              -.939           -1            -.024

Now 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++.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
siddharth
  • 579
  • 1
  • 8
  • 18
  • 2
    keywords: 'read fixed with columns in c++', you should check your data format whether it is a reliable "fixed with format" (retaining all spaces and line lengths). Then, split your input line at the correct positions and scan these blocks as integers or whatever. – rubber boots Feb 16 '11 at 13:45

2 Answers2

3

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

Community
  • 1
  • 1
Matt
  • 3,778
  • 2
  • 28
  • 32
0

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.