Thread: How to subtract string arrays?

  1. #1
    Registered User
    Join Date
    Jan 2012

    How to subtract string arrays?

    I was wondering if someone could tell me how to subtract two string arrays. I use getline() that is why the array is a string. It is in my main, but the below code is my function.
    Also the data inside the array is just numbers such as: 88 91 100 etc, Just want to subtract those numbers

    I Get the errors from these two lines of code.
    HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-16];
    HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-1];

    void algor1(int sizeCASE1, int columnCASE1, string dataCASE1[]){    
        string HUFFMAN[256];
        ofstream outStream;
            cout << "Output file opening failed.\n";
        HUFFMAN[0] = dataCASE1[0];
        for(int i = 1; i < sizeCASE1; i++)
            if(i == columnCASE1)
                HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-16];
                HUFFMAN[i] = dataCASE1[i] - dataCASE1[i-1];
        for(int j = 0; j < sizeCASE1; j++)
            outStream << HUFFMAN[j];

    Last edited by geewhan; 06-29-2012 at 05:26 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    You need to extract the numbers from the string in some suitable order, do the subtraction, and (if you need the results as a string) write the results back to the string in some manner.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    If you get errors, that's great; all you need to do now is post them.
    No sense keeping them to yourself, share 'em around.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-27-2011, 05:40 PM
  2. shift-and-subtract divider
    By tox0tes in forum C Programming
    Replies: 1
    Last Post: 01-17-2010, 01:22 AM
  3. Replies: 15
    Last Post: 01-24-2008, 09:40 PM
  4. Add, Subtract Calculator...
    By Crash1322 in forum C++ Programming
    Replies: 8
    Last Post: 12-14-2003, 11:38 PM
  5. How to add/subtract from array element...
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 05-01-2002, 10:04 PM