Stack Memory Corrupted?

Hi!

I am using an array to store some characters, but I get this error:

 
Stack around the variable 'output' was corrupted


Here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
string input;
	int a, b, c;
	int index = -1;
	char output[255];
	a = rand() % 10;
	b = rand() % 10;
	c = rand() % 9;
	cin >> input;
	for (char c : input)
	{
		int numeric = getNumber(c);
		numeric += a + b + c;
		if (numeric > 26)
		{
			numeric -= 26;
		}
		output[index++] = getCharacter(numeric);
	}
	for (char c : output)
	{
		cout << c;
	}
	cout << endl;

I've looked online for some answers, but nothing really helped :(
What can I change and why does this happen?
index++ returns the value of index before it was incremented so on the first iteration you will try access output[-1] which doesn't exist.
Last edited on
Okay, I'll set index to 0 instead of -1
Topic archived. No new replies allowed.