Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

reading and storing data

sabsLONsabsLON Member Posts: 2
Hi, I am writing a mathematical program in C++ and am having a couple of problems.

The user inputs a number of entries in the form
( type parameter1 parameter2 weight ) eg

>> ( alpha 2 3 0.4 ) + ( gamma 6 2 0.6 )

The above is one input with 2 entries. There are only 5 types of names, and the type of the name determines the manner in which the parameters in an entry are used.

The user can enter as many entries as he wishes.

What I am having problems with is how to read the entries and
how to store them.

Im thinking of using arrays, and storing similar elements in
the same array, so
I would get something like below

name_array[0] = alpha name_array[1]= gamma
param1_array[0] = 2 param1_array[1] = 6
param2_array[0] = 3 param2_array[0] = 2
weight_array[0] = 0.4 weight[1] = 0.6

What I would like to know is:
How to read the input and store the individual elements of an entry??
How would I read the input so that the program recognises what it is reading is the name, or what it is reading is the 2nd parameter. The program should be able to cope with more than 1 whitespace between different elements in an entry.

any help or ideas would be really appreciated.

Thanks

Comments

  • WuduWudu Member Posts: 25
    : Hi, I am writing a mathematical program in C++ and am having a couple of problems.
    :
    : The user inputs a number of entries in the form
    : ( type parameter1 parameter2 weight ) eg
    :
    : >> ( alpha 2 3 0.4 ) + ( gamma 6 2 0.6 )
    :
    : The above is one input with 2 entries. There are only 5 types of names, and the type of the name determines the manner in which the parameters in an entry are used.
    :
    : The user can enter as many entries as he wishes.
    :
    : What I am having problems with is how to read the entries and
    : how to store them.
    :
    : Im thinking of using arrays, and storing similar elements in
    : the same array, so
    : I would get something like below
    :
    : name_array[0] = alpha name_array[1]= gamma
    : param1_array[0] = 2 param1_array[1] = 6
    : param2_array[0] = 3 param2_array[0] = 2
    : weight_array[0] = 0.4 weight[1] = 0.6
    :
    : What I would like to know is:
    : How to read the input and store the individual elements of an entry??
    : How would I read the input so that the program recognises what it is reading is the name, or what it is reading is the 2nd parameter. The program should be able to cope with more than 1 whitespace between different elements in an entry.
    :
    : any help or ideas would be really appreciated.
    :
    : Thanks
    :

    You want to read/write files ? or strings ?
    Files -> take a look at these WinAPI-functions WriteFile() and ReadFile()
    Strings -> sscanf() and sprintf()
Sign In or Register to comment.