# calculating character frequencies from a txt file

in C#
Im new to C#.......im just wondering how to start this calculation....this is an eg. of the output i hav so far..i can get total lines, characters etc..

Total lines = 10
Total characters = 80
Mean characters per line = 8.00
With a standard deviation = 4.64
Lines range from 2 to 15 characters long

to calculating character frequencies i was thinking of making an array with 256 elements in it...dont know...any ideas

• : Im new to C#.......im just wondering how to start this calculation....this is an eg. of the output i hav so far..i can get total lines, characters etc..
:
: Total lines = 10
: Total characters = 80
: Mean characters per line = 8.00
: With a standard deviation = 4.64
: Lines range from 2 to 15 characters long
:
: to calculating character frequencies i was thinking of making an array with 256 elements in it...dont know...any ideas
:
The array is a fine solution. The only thing is that the .Net char type represents a Unicode character. There are 65,536 different Unicode characters...sizeof(char) = 2 in .Net.

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl

• : The array is a fine solution. The only thing is that the .Net char type represents a Unicode character. There are 65,536 different Unicode characters...sizeof(char) = 2 in .Net.
:
:
: Greets,
: Eric Goldstein
: http://www.gvh-maatwerk.nl
:
:
: Thank you....but i am still finding it hard to start...im just wondering how to use the array to do this..

in the calling program,, ive got
[code]
Console.WriteLine("Character Frequencies:");
for (int c = 0; c < 256; c++)
{
if(stats.FetchCharacterFrequency(c) > 0)
Console.WriteLine(" {0} = {1}", (char)c, stats.FetchCharacterFrequency(c));
}
[/code]

in my text statistics class i will make the array...just dont know how to make this array work......

• [b][red]This message was edited by tsagld at 2006-8-1 0:58:53[/red][/b][hr]
:
: : The array is a fine solution. The only thing is that the .Net char type represents a Unicode character. There are 65,536 different Unicode characters...sizeof(char) = 2 in .Net.
: :
: :
: : Greets,
: : Eric Goldstein
: : http://www.gvh-maatwerk.nl
: :
: :
: : Thank you....but i am still finding it hard to start...im just wondering how to use the array to do this..
:
: in the calling program,, ive got
: [code]
: Console.WriteLine("Character Frequencies:");
: for (int c = 0; c < 256; c++)
: {
: if(stats.FetchCharacterFrequency(c) > 0)
: Console.WriteLine(" {0} = {1}", (char)c, stats.FetchCharacterFrequency(c));
: }
: [/code]
:
: in my text statistics class i will make the array...just dont know how to make this array work......
:

[code]
/* GetNextChar and EOF are pseucode. I assume you have code for that already.
*/

int [] frequencies = new int [256];

char c = GetNextCharFromStream();
while (!EOF)
{
frequencies[(int)c]++;

c = GetNextCharFromStream();
}
[/code]

Greets,
Eric Goldstein
http://www.gvh-maatwerk.nl

• : [code]
: /* GetNextChar and EOF are pseucode. I assume you have code for that already.
: */
:
: int [] frequencies = new int [256];
:
: char c = GetNextCharFromStream();
: while (!EOF)
: {
: frequencies[(int)c]++;
:
: c = GetNextCharFromStream();
: }
: [/code]
:
:
: Greets,
: Eric Goldstein
: http://www.gvh-maatwerk.nl
:
:
: Thanks again. I am unsure of what the GetNextCharFromStream method would look like.
:
:

• Never mind...I have got my program working now..Thank you for your help