Help Understanding Array

How to put the alphabet into an array?


1
2
for (int i = 0; i < 26; i++)
//wat do here 
Last edited on
bump for clarity
closed account (48T7M4Gy)
Hint: Look up the ASCII table and take advantage of the fact that your char value of i added to 'a' is very useable.
Last edited on
Either
1
2
const char alphabet[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
                            'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' } ;


Or (ignore the last null character):
const char alphabet[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; // use the first 26 elements in positions [0,25]
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
	char start;
	char alphabet[26];

	std::cout << "Where do you want to start a, A etc ? ";
	std::cin >> start;

	for (int i = 0; i < 26; i++)
	{
		alphabet[i] = i + start;
		std::cout << alphabet[i];
	}
}
thanks kemort works great. Idk what that ascii dude was talking about but I spent like an hour looking through ancient nasa documents trying to decode the secrets of ascii.
closed account (48T7M4Gy)
Sounds like paranoia might set in if I don't give you a simpler solution to my ASCII reference:
http://www.cplusplus.com/doc/ascii/?kw=ASCII
Topic archived. No new replies allowed.