- Jun 7, 2000
- 481
- 0
- 0
Hey guys, got a little question here.
Here is the deal, I am writing a constructor called polynomial that accepts as its sole parameter a char* list. Included in this list is a variable amount of coefficients and there exponent.
example:
polynomial:
olynomial(char* p) {...}
It would get called in a way like this: polynomial("2.4 5 4 5.6 4.5 0 1.2 2.3") = 2.4^5, 4^5.6, 4.5^0, 1.2^2.3
I have 2 data members,
float coeff, exp;
Now, I want to be able to read in the first "word" in the char string as coeff, then the next as exp, then repeat until p == NULL.
I think it should be something like this:
while( p != NULL ) {
// Read in the first "word" as the float variable, coeff. Probably going to need an atof( )
// Read in the 2nd "word" as exp, same as above;
// Put into a linked list (this is not important in regards to my trouble)
}
So does anyone have any idea how to read from my char* stream into a float variable?
Thanks!!!
Here is the deal, I am writing a constructor called polynomial that accepts as its sole parameter a char* list. Included in this list is a variable amount of coefficients and there exponent.
example:
polynomial:
It would get called in a way like this: polynomial("2.4 5 4 5.6 4.5 0 1.2 2.3") = 2.4^5, 4^5.6, 4.5^0, 1.2^2.3
I have 2 data members,
float coeff, exp;
Now, I want to be able to read in the first "word" in the char string as coeff, then the next as exp, then repeat until p == NULL.
I think it should be something like this:
while( p != NULL ) {
// Read in the first "word" as the float variable, coeff. Probably going to need an atof( )
// Read in the 2nd "word" as exp, same as above;
// Put into a linked list (this is not important in regards to my trouble)
}
So does anyone have any idea how to read from my char* stream into a float variable?
Thanks!!!