Need Clarification On Using Arrays To Count Characters

I've been given an assignment in my programming class to write a program that prompts the user to enter a sentence and then the program tallies each character in the sentence and displays the count. It needs to do this for any and all uppercase, lowercase, and number characters in the sentence. I've got the entire program written and working properly up until this point. When I asked my professor how I should go about doing this he suggested I use a char array to offset the array containing the sentence and search for ASCII characters and fill the buffer at the position of the character (i.e. 97 for lowercase A). Or something like that. He then suggested I use type casting on the ASCII array so the output displays the character and the number of times it appears in the sentence as indicated by the incremented buffer. Below is some code I wrote illustrating how I understood his instructions.

1
2
3
4
5
6
	for (int i = 0; i < letterCounter; i++)
	{
		if (userLine[i] == number[97])
			number[97]++;
	}
	cout << number[97] << endl;


As expected it doesn't work but hopefully it shows you what he was trying to tell me. If I understood what he was telling me better maybe I could explain it to you better, but then I probably wouldn't need to ask for help if that was the case.

I didn't want to post my entire code in case some of my classmates also came here looking for advice on this assignment. If you need to see more of my code I'd be happy to PM it to you. Thanks for taking a look at my problem.
It's simplier:
1
2
3
4
5
6
7
8
9
10
11
	int number[256] = { }; // Initialize with 0

	for (int i = 0; i < letterCounter; i++)
	{
		number[userLine[i]]++;
	}
	for (int i = 0; i < 256; i++)
	{
		if(number[i] > 0)
		  cout << (char) i << ": " << number[i] << endl;
	}
Thank you very much for solving my problem. Seeing as this is homework I promise I won't just copy and paste it, I'll toy with it and learn how it ticks. Thank you again.
Topic archived. No new replies allowed.