What is problem with my code?

#include
#include

using namespace std;
void MaxOccurence(char str[1000]){
pair<char,int> str1;
int n = 1;
int a =0;
// to find the size of entered string.
while(str[a] != β€˜\0’){
n++;
a++;
}
int sum;
// to calculate the occurence of each alphabet in the string.
// and storing them in another pair with its number of occurences.
for(int i=0;i<n;i++){
sum =1;
for(int j=i+1;j<n;j++){
if(str[i]==str[j]){
sum++;
}
}
str1.first[i] = str[i];
str1.second[i] = sum;
}
int max = 0;
char chmax;
// finding out the max occurence and its corresponding alphabet.
for(int i=0;i<n;i++){
if(str1.second[i]>max){
max = str1.second[i];
chmax = str1.first[i];
}
}
// print the most occured alphabet.
cout<<chmax;
}
int main() {
char str[1000];
cin>>str;
MaxOccurence(str);

return 0;

}

hi @yamangoyal100_ff74db54bdf01539 share the code on ide.codingblocks.com
or refer https://www.geeksforgeeks.org/return-maximum-occurring-character-in-the-input-string/

how to share code on ide.codingblocks.com??

i need to understand what is the error with my code although i have understand the solution from Gfg.


I am getting this error with this code:->
#include<bits/stdc++.h>
#define ASCII_MAX 256
using namespace std;

void maxOccurence(char *str)
{
int count[ASCII_MAX] = {0};
int len = strlen(str);
int max = 0;
char result;
for (int i = 0; i < len; i++) {
count[str[i]]++;
if (count[str[i]] > max) {
max = count[str[i]];
result = str[i];
}
}
cout << result;
}

int main()
{
char str[] = {" "};
cin >> str;

maxOccurence(str);
return 0;

}

it is working in vs-code.

hi @yamangoyal100_ff74db54bdf01539 the code is not readable when u share here
go to ide.codingblocks.com

  1. login
  2. write
  3. save
  4. send the url

not able to access shareable code…???

After writing code and savings the url of the page should change send that url

this is second code;