hello, I have to parsing a string like this:
char * = "10 20 30 40";
and put its number into a vector<double>
I thought to use strchr() and atof() and it's seems ok but to say the truth the line could be at times a little different:
char * = "10 20 30 40 ";
char * = "10,20,30,4 0";
char * = "10, 20,30, 40 ";
char * = "10 20,30 40 ";
all these above are valid line; instead this isn't':
char * = "10 20 30 40,"; (comma ate the end isn't accetable)
The number in the string must have a separtor: it could be a white space (or \t) or other (e.g. a comma); Can I work with strchr and atof.....or Do I need a little parser? I tried with the first way but the code seems not good....any suggest? (to note: I need to write the code on my own and not to use parsers generators)....
thanks.
char * = "10 20 30 40";
and put its number into a vector<double>
I thought to use strchr() and atof() and it's seems ok but to say the truth the line could be at times a little different:
char * = "10 20 30 40 ";
char * = "10,20,30,4 0";
char * = "10, 20,30, 40 ";
char * = "10 20,30 40 ";
all these above are valid line; instead this isn't':
char * = "10 20 30 40,"; (comma ate the end isn't accetable)
The number in the string must have a separtor: it could be a white space (or \t) or other (e.g. a comma); Can I work with strchr and atof.....or Do I need a little parser? I tried with the first way but the code seems not good....any suggest? (to note: I need to write the code on my own and not to use parsers generators)....
thanks.
Comment