Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following information:

John J Johnson    100  90  79 100  65  81
Ben A Franklin        100 100 100  78  88  98
Patricia T McMillan    60  90  75  83  91  79
Arthur D Dent          78  88  98  75 100  78
Ford M Prefect         99  99  99 100 100 100  


How ca I read every column to a different 1 dimensional array??? A 2d array would be a good solution, but I was ask to read to differents 1 dimensional array. Please anyone???
Posted
Comments
[no name] 10-May-14 20:11pm    
You would need to tokenize each line which would give you your "columns" then go through your tokens and add the columns to your arrays.
Sergey Alexandrovich Kryukov 10-May-14 20:23pm    
It seems to be quite easy, so the question is: what have you tried so far?
—SA

1 solution

You can read lines with File.ReadAllLines() which will give you an array of strings (lines).

You can split the line with line.Split(' ') where line is a line from the above array of lines and you are splitting on spaces, which will give you a array of words fro the lines.

You should be able to do what you want from there.

[Edit - my apologies for not seeing the c++]
For c++ see this for reading lines : http://www.cplusplus.com/forum/beginner/74757/[^]
and this for splitting : http://stackoverflow.com/questions/5888022/split-string-by-single-spaces[^]
 
Share this answer
 
v2
Comments
Emre Ataseven 11-May-14 6:15am    
I think he needs C++ code, not C#.
Mehdi Gholam 11-May-14 13:21pm    
Thanks, I have edited the solution.
Maciej Los 11-May-14 16:25pm    
Up-voted!
Mehdi Gholam 12-May-14 1:58am    
Thanks Maciej!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900