Populate array from text file - help

  • Thread starter Thread starter Marcelo
  • Start date Start date
M

Marcelo

Hi,

I have to do the following, and would like you suggestions
on how I could achieve it the best way:

I have a text file in the following format:

12345 54321 98765 56789
(3 spaces between numbers)

Those are reference numbers for monetary values. They are
associated with values in this format

1.00 2.00 ... 9.00 10.00 20.00 ... 90.00 100.00 200.00 ...
900.00 1000.00 2000.00 ... 9000.00...

Which is the best way for me to do it? Because I have to
do the following: given the monetary value 123.00:

3.00 x 1 = 3.00
2.00 x 10 = 20.00
1.00 x 100 = 100.00

And supposing:

array[3] = 12345
array[20] = 23456
array[100] = 34567

I would sum those values to obtain a key to validate my
text file in my server.

Everything is implemented, expect for the part in which
the array is populated (i'm working with a "fake" array).

Any help will be very appreciated. And no, this is not
homework. I'm a newbie with C++ and I'm implementing a
component to process messages of payment. That's why I'm
asking help :)

TIA

Marcelo
 
Hello,

You would use the fopen()/fgets()/fclose() to read from file.
You would then use strstr() or strtok()/strtol() to convert strings to
integers as you're parsing the data you read.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top