Compression of strings

#include
#include
using namespace std;
char getmax(char *str){
int count[256]={0};
int len = strlen(str);
for(int i=0;i<len;i++){
count[str[i]]++;
if(str[i]!=str[i+1]){
cout<<str[i]<<count[str[i]];
}
}
return 0;
}
int main() {
string s;
cin>>s;
char *str=(char *)s.c_str();
getmax(str);
return 0;
}

as i m unable to other ides too,please review this only

Hi @aditi2512201012019

Your code is failing for inputs like: aaabbcca
Your output : a3b2c2a4
Correct Answer : a3b2c2a1
So make count[str[i]] = 0 when you enter if condition in loop after printing the letter and it’s frequency.

Corrected Code : https://ide.codingblocks.com/s/198595

Hope it Helps.