*arsing string hel* me *lease

hi guys i need your help.
i have a text like below here and i need to parsing
this string and return float value after character.

"A0 B1.4 C3.5 D4.7"

the result must be
A=0;
B=1.4;
C=3.5;
D=4.7;

hmm but the problem is i can't use string.h or declare string variable. i hate this... :(

any suggestion??
Assuming you never use any letters other than A-Z, this problem is quite easy. Declare two sets of variables with variants of those names (one stores floats, the other is a char[] that stores up to... say eight characters, initialize them to something to avoid confusion later, get a character, determine which char * variable to use to store the numbers gotten by getline(variable, 8, ' ');, and use atof().

You may want to use a switch statement, and you may want to use a loop that continues until a newline is read by cin.get().

Assuming your sets of variables are 26-element-long arrays, to determine which space to read into or out of, subtract the number 65 from the character. Here's why:
http://asciitable.com/

Useful links:
http://cplusplus.com/reference/iostream/istream/get/
http://cplusplus.com/reference/iostream/istream/getline/
http://cplusplus.com/reference/clibrary/cstdlib/atof/

NOTE: Using a map<> is a better solution, but that might be a bit hard for you now (prerequisites: basic understanding of using templates and using classes). If you think you can understand it, though, then...

http://cplusplus.com/reference/stl/map/


-Albatross
Last edited on
hmm.. @Albatross...thx for suggestion

but i can't use that.. because i don't use C/C++ compiler... hmm.. the only one i can use is strtod()... i us that think and works if there is no whitespace... otherwise get error...

maybe anyone can help me to do this stuff..
i don't know why but my machine is lack of c/c++ library...

:(
Subchan wrote:
but i can't use that.. because i don't use C/C++ compiler... hmm.. the only one i can use is strtod()... i us that think and works if there is no whitespace... otherwise get error...

maybe anyone can help me to do this stuff..
i don't know why but my machine is lack of c/c++ library...


Then how in the twelve days of Christmas are you running your C++ code?

-Albatross
Last edited on
Topic archived. No new replies allowed.