CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Threaded View

  1. #5
    Join Date
    Aug 2010
    Posts
    16

    Re: Segmentation Fault

    here is the implementation for >> and operator+ for bigint

    Code:
    std::istream& operator>> (std::istream& in, bigint& num)
    {
            num.initialize();
            char ch;
            in >> ch;
            while (ch != ';')
            {
                    num.push_back(ch-'0');
                    in >> ch;
            }
            return in;
    }
    
    
    bigint bigint::operator+ (bigint rhs) const
    {
            bigint result;
            int rhs_max = rhs.size();
            int lhs_max = size();
            int max;
            if (rhs_max > lhs_max)
                    max = rhs_max;
            else
                    max = lhs_max;
            int idx = 0;
            int temp;
            while (idx < max)
            {
                    temp = digits[idx] + rhs.digits[idx] + result.digits[idx];
                    int i = 0;
                    while (temp != 0)
                    {
                            result.digits[idx+i] = (temp&#37;10);
                            temp = (temp/10);
                            ++i;
                    }
            ++idx;
            }
            return result;
    }
    I appologize for not using the code tags (new here) and its been a very long week so im a little out of it
    Last edited by originalmoose; September 29th, 2010 at 05:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured