0

I'm working on a homework/project to tokenize a set of operands (double) and operators as inputs. It's been going well enough and I have been able to finish it by implementing my own tokenizer but when I tested my output exe with digits greater than 7 I get a random output, which probably means I got "fresh" memory location (eg 123456 is OK, but 1234567 and higher digit numbers are no good).
Here's a code snippet:

token::token(istream& f)
{
    string g;
    f>>g;
    int gpos=0;
    //checks for presence of a decimal point
    bool thereisadecimal=false;
    do
    {
        if(id_operand.find(g[gpos])!=string::npos)
        {
            try
            {
                //checks for decimal points to check if invalid input
                    //checks if value has already been set 
                    //     (it's on a loop for scan)
                    if(_type!=operand_)
                    {
                    _type = operand_;
                    _value = strtod(g.c_str(),NULL);
                    }
                }
            }...
      ++gpos;
    }while(g.length()!=(gpos-1));
....

When I try the inputs greater than six digits I get erroneous outputs. Why is this happening and is there a way to go around this?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Repurcussion
0

Do you have a specific test case?

Are you sure it's not something like
1234567 being displayed as say 1.23456E6 (for example).

0

I'm sorry. this was a stupid question. I am VERY SORRY!!!

I hadn't realized that the output was set in scientific notation. *smacks face on a math, physics, and computer science book*

really sorry. will double check for own stupidity next time I'm tempted to post.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.