Unhandled exception?

I seem to be getting this error, but I am unsure how to solve it. It used to work, but now it doesn't. Error: Unhandled exception at 0x01101ad2 in SpamBot.exe: 0xC0000005: Access violation reading location 0x01116000.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 #include <iostream>
#include <string>
#include <windows.h>
#include <WinBase.h>
#include <stdio.h>
using namespace std;
int i = 0;
int size;
char ToKey[6000];
bool Spam = false;
string Chars;
int a;


void Sendkey(char Key1) {
	keybd_event(VkKeyScan(Key1),0x9d,0,0);
	keybd_event(VkKeyScan(Key1),0x9d,KEYEVENTF_KEYUP,0);

}
int main() {
	auto size = sizeof(*ToKey)/sizeof(ToKey[0]);
	cout << "Enter Text." <<endl;
	cin >> ToKey;
	cout << "Put in  the word 'start' to activate it!" << endl;
	cin >> Chars;
	while(true) {

		if (Chars=="start") {
			if (Spam == false) {
			Spam = true;
			}
			else{
			Spam = false;}}
		if (Spam) {Sendkey(ToKey[i]);}
		if (i==size) 
		{
			Sleep(10);}
	i++;}
	cin.get();
	return 0;
}
auto size = sizeof(*ToKey)/sizeof(ToKey[0]);

size will always be 1. You are effectively dividing the same number by itself.


Also, you never stop 'i' from incrementing, so it will increment far beyond 'size', and far beyond the end of your buffer, and far into bad memory -- which is what is causing your program to crash.
Topic archived. No new replies allowed.