Populate array from text file - help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcelo

    #1

    Populate array from text file - help

    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
  • lallous

    #2
    Re: Populate array from text file - help

    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.

    --
    Elias


    "Marcelo" <sms2k@h0tmail. 08ujkllk98yu2js 83.com> wrote in message
    news:0b5801c386 c6$e50a2600$a40 1280a@phx.gbl.. .[color=blue]
    > 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[/color]


    Comment

    Working...