Read file of char and int into an array

Hi guys,

I have a .txt file which contains 3 columns of data. Each column represents a integer to be used to set a read write flag, a hexadecimal number used to represent a memory location and a hexadecimal number used to represent a byte/word of data respectively. They are all separated from each other by a single white space.

An example to illustrate the format is as follows:

1 0x00000000
1 0x00000004
0 0x00000800 0x00000000
1 0x00000008
1 0x0000000C
1 0x00000010
0 0x00000804 0x0000000A
0 0x00000808 0xFFFFFFFF
0 0x0000080C 0x5A5A5A5A
1 0x00000014

I need to place this data in a two dimensional array of 3 columns and some user specified number of rows. The trouble is that I have been unable to read the data in as integers, I have only found examples for dealing with strings, for example the getline(file, string) function. Is there an equivalent function defined somewhere for passing a stream of integers into an array? Or should it be done as a set of characters?

How would you go about this basically?

Many thanks for your time and any suggestions!


closed account (o3hC5Di1)
Hi there,

I think you may want to give sscanf() a try for this.

Have a look at: http://www.cplusplus.com/reference/clibrary/cstdio/sscanf/

Hope that helps.

All the best,
NwN
Topic archived. No new replies allowed.