0

Hi there,

I am trying to read integers from a file and store them into an array but I have no idea how to do it. The file is a text document whos contents are arranged like an adjacency list.

Here is an example file:

0 : 2,4,5,6,10
1 : 3,9,10
2 : 0
3 : 1,8
4 : 0,7,9,10
5 : 0,1,3,6
6 : 0,5,7
8 : 3,9
9 : 1,4,3
10: 0,1,4

To the left of the colon will represent the indices of the array and to the right represent values which I will store in another array.

Any ideas on how to do this?
Also, is it possible to count the number of lines first?

3
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by Odc
0

I am trying to read integers from a file and store them into an array but I have no idea how to do it. [...]

One step at a time.
Start learning how to assign values to arrays.
Learn how to read a single or group of characters from a file.
After that it is just a matter of parsing what's read and manipulating the data.

0

Maybe I worded it incorrectly. I know how to manipulate arrays etc but I don't know how to parse a file properly.

0

Maybe I worded it incorrectly. I know how to manipulate arrays etc but I don't know how to parse a file properly.

Do you know how to open a file and read from it?

0

Nope :S

I feel like an epic noob lol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.