My program must read a file and count how many times each letter comes up using vectors[27]. besides main there will be 2 required functions.
int char2int(char arg)
void display(const vector<int> & counters)
the file has numbers to but those should be read as a O. need help please help!

Recommended Answers

All 2 Replies

>My program must read a file and count how many times each letter comes up using vectors[27].

This seems like a faily simple problem, but why use vectors for this?
You don't even need a char2int function as conversion from char to int is automatic. Simply make an array of 26 ints and loop through each character while incrementing the counter for that particular letter.

I just made a snippet to do the same, except without reading a file. [link]

But the first thing you need to do is learn how to open files and read the data, here's a tutorial. [link]

Hope this helps.

the file has numbers to but those should be read as a O. need help please help!

> You read a whole line from the file into a string variable and you loop through the string character by character and you evaluate if the character meets the following condition to be counted: the character is in between [a-z] and [A-Z] otherwise you've three possibilities:

-> The character indicates the beginning of a number
-> The character is a digit and should be counted as an 'O'
-> You don't have to count anything

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.