I have written a C program. It's a character counting program. I will give input as below
Input:    ABCAPPPRC
And need as output:   A2B1C2P3R1.
But it gives output as A2B1C2A1P3P2P1R1C1. It basically doing as per the logic I have written in program. But I don't want to count the characters of string which have already been counted. Can you suggest what logic I should implement for this?
#include <stdio.h>
int main()
{
        char str[30]= "ABCAPPPRC";
        char strOutPut[60]="";
        char *ptr= &str, *ptr2=&str;
        char ch='A';
        int count=0;
        puts(str);
        while (*ptr !=NULL)
        {
                count =0;
                ch = *ptr;
                while (*ptr2!= NULL)
                {
                        if (*ptr2 == ch) count++;
                        ptr2++;
                }
                printf("%c%d",*ptr, count);
                ptr++;
                ptr2 = ptr;
        }
}