0

Hello,

I have a problem about counting consequtive characters, here my code

char query[] = "tttthe oneZZZZZ    trully loveeee";


void cntfreq(char A[])
{
    int j;
    int k=0;
    j = 1;
    while (A[j] != '\0')
    {
        if (A[j-1] == A[j])
        {
            ++k;
            cout<<k<<"\t"<<A[j]<<endl;
        }
        else
            k = 0;
        ++j;
    }
}

Suppose that also my char is the following as an input:

char query[] = "tttthe oneZZZZZ    trully loveeee";

I success in counting the consequtive characters, but it counts minus 1, for example there are 4 consecutive char 't' but it says 3 't' or 5 'Z' character, but it outputs 4 Z are here. Actually, I found the problem in which occurs at checking last consecutive characters, in other words, when it checks t and h or last character e and '\0' character at the end of file. I found the problem in my mind, but how I translate in C++ code ? It is my part of my homework, honestly but it is not C++ homework; it is Mips homework, I'll try to translate this "working/proven" C++ code into Mips language, I hope.

Thanks.

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by firstPerson
This topic has been dead for over six months. 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.