Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6550005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:09:47+00:00 2026-05-25T12:09:47+00:00

i wrote following code to count occurance of characters in given char array #include

  • 0

i wrote following code to count occurance of characters in given char array

#include <iostream>
#include <string>
using namespace std;
int main(){

char f[]={'a','a','b','c','c','d','d','f','e','e'};
int n=sizeof(f)/sizeof(char);
char max=f[0];
for (int i=1;i<n;i++)
{
    if(f[i]>max)
    {
        max=f[i];
    }
}

int m=(int)(max)+1;
int  *b=new int [m];

for (int i=0;i<n;i++)
{
    b[(int)(f[i])]++;
}

for (int i=0;i<m;i++)
{
    if(b[i]!=0)
    {
    cout<<(char)(i)<<" occurs  "<<b[i]<< "times "<<endl;   
    }      
}

return 0;
}

but it shows very bad result

 occurs  -842150451times
☺ occurs  -842150451times
☻ occurs  -842150451times
♥ occurs  -842150451times
♦ occurs  -842150451times
♣ occurs  -842150451times
♠ occurs  -842150451times
 occurs  -842150451times
 occurs  -842150451times
         occurs  -84215045

 occurs  -842150451times
♂ occurs  -842150451times
♀ occurs  -842150451times
 occurs  -842150451times
♫ occurs  -842150451times
☼ occurs  -842150451times
► occurs  -842150451times
◄ occurs  -842150451times
↕ occurs  -842150451times
‼ occurs  -842150451times
¶ occurs  -842150451times
§ occurs  -842150451times
▬ occurs  -842150451times
↨ occurs  -842150451times
↑ occurs  -842150451times
↓ occurs  -842150451times
→ occurs  -842150451times
← occurs  -842150451times
∟ occurs  -842150451times
↔ occurs  -842150451times
▲ occurs  -842150451times
▼ occurs  -842150451times
  occurs  -842150451times
! occurs  -842150451times
" occurs  -842150451times
# occurs  -842150451times
$ occurs  -842150451times
% occurs  -842150451times
& occurs  -842150451times
' occurs  -842150451times
( occurs  -842150451times
) occurs  -842150451times
* occurs  -842150451times
+ occurs  -842150451times
, occurs  -842150451times
- occurs  -842150451times
. occurs  -842150451times
/ occurs  -842150451times
0 occurs  -842150451times
1 occurs  -842150451times
2 occurs  -842150451times
3 occurs  -842150451times
4 occurs  -842150451times
5 occurs  -842150451times
6 occurs  -842150451times
7 occurs  -842150451times
8 occurs  -842150451times
9 occurs  -842150451times
: occurs  -842150451times
; occurs  -842150451times
< occurs  -842150451times
= occurs  -842150451times
> occurs  -842150451times
? occurs  -842150451times
@ occurs  -842150451times
A occurs  -842150451times
B occurs  -842150451times
C occurs  -842150451times
D occurs  -842150451times
E occurs  -842150451times
F occurs  -842150451times
G occurs  -842150451times
H occurs  -842150451times
I occurs  -842150451times
J occurs  -842150451times
K occurs  -842150451times
L occurs  -842150451times
M occurs  -842150451times
N occurs  -842150451times
O occurs  -842150451times
P occurs  -842150451times
Q occurs  -842150451times
R occurs  -842150451times
S occurs  -842150451times
T occurs  -842150451times
U occurs  -842150451times
V occurs  -842150451times
W occurs  -842150451times
X occurs  -842150451times
Y occurs  -842150451times
Z occurs  -842150451times
[ occurs  -842150451times
\ occurs  -842150451times
] occurs  -842150451times
^ occurs  -842150451times
_ occurs  -842150451times
` occurs  -842150451times
a occurs  -842150449times
b occurs  -842150450times
c occurs  -842150449times
d occurs  -842150449times
e occurs  -842150449times
f occurs  -842150450times

please help me what is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:09:48+00:00Added an answer on May 25, 2026 at 12:09 pm

    You have to initalize the “malloc”ed (new) area to 0, it contains garbage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote the following code.... #include< iostream> #include< fstream> using namespace std; int main()
I wrote the following code: #include <iostream> class A { public: A(){ std::cout <<
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I needed some simple string encryption, so I wrote the following code (with a
I recently wrote the following C code using sysinfo systemcall to display system statistics,
I just wrote the following line of code: if (++(data_ptr->count) > threshold) { /*...*/
I wrote the following code to read the content of a file: #include <ifstream>
i wrote following code to create a linkbutton programmatically, but its showing like lable
if wrote the following code and do not understand why the trace returns false:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.