Member Avatar for Odc

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?

Recommended Answers

All 6 Replies

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.

Member Avatar for Odc

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

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?

Member Avatar for Odc

Nope :S

I feel like an epic noob lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.