PDA

View Full Version : Double value holding for array?


dwj100uni
10-25-2005, 07:30 PM
Hi there, having a bit of trouble on a project I am working on.

Basically I need to read in a set of ASCii characters (could be any of 256) from a file and keep a total of each, i.e. 2 A's, 7 B's 8 C's, etc.

I thought that a double linked list was what i needed, however after research i can see that that is only really used for to allow movement forewards and backwards between nodes, and i am not sure how i could get an array list to hold two values (i.e. the character it represents and the no of occurances), however, i could use one as i know the max number would be 256.

If anyone could shed anylight on this it would be greatly appreciated,

Thanks

David

oracleguy
10-25-2005, 08:12 PM
You could use either a two dimensional array or a struct. If you want to use a linked list, you could use it in combination with a struct but it isn't necessary unless you only want add array elements for characters it has found. Otherwise the number of characters you are dealing with is constant and can be a static array.

hyperbole
10-26-2005, 06:21 PM
Why not just create an array of 256 elements and each time you read a character, use it as an index into the array and increment that element.

When you have read the entire file, the 'A' == 65th element of the array would contain the number of 'A's in the file, the 66th element would contain the number of 'B's, etc.



.