Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have this code:

C#
private void btn_Click(object sender, EventArgs e)
{
    byte[] data = File.ReadAllBytes("a.txt");

    int[] totals = new int[256];

    foreach (byte in data)
    {
        ++totals[b];
    }
}


The output is this: http://i45.tinypic.com/2nquqhi.png[^]

But how can i show the frequency(occurrence) of each character in a.txt also?
and store it in: long[] freqar=new long[256];
Posted

1 solution

No! Do this:
C#
foreach(byte value in data)
    ++totals[value];

Can you see you bug now? Now you have occurrences. Hope you can continue and calculate frequency by yourself.

—SA
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 29-Jan-13 19:34pm    
[OP commented:]

Ahh thanxs

++totals[b]
++far[b]

did the trick, thanxs for the advice!
Sergey Alexandrovich Kryukov 29-Jan-13 19:35pm    
If so, please accept it formally (green button) — thanks.

Please, next time don't put a post like that as a "solution". "Add your solution here" is reserved for the case when you try to provide some help in response to some member's question. Besides, no one gets a notification. Instead, please comment on any other post, reply to existing comment. In other cases, use "Improve question", above.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900