I dont know why this crashes on my IDE

This works fine on an online compiler but I need to edit it on my IDE but it crashes on Qt. Can anyone see why?


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string>
using namespace std;

class CIS14 {
public:

    int getNumPossibleSigns(string* letterInventory, string* addresses, int length);
};

int CIS14::getNumPossibleSigns(string* letterInventory, string* addresses, int length)
{
    string foo;
    size_t found;
    int i,n,retval = 0;
    do{
        string temp = *letterInventory;
        n = 0;
        do{

            if (addresses[i].substr(n,1) == " " || addresses[i].substr(n,1) == "\t"){
                n++;
                continue;
            }

            foo = addresses[i].substr(n,1);
            found = temp.find_first_of(foo);


            if (found == -1){
                break;
            }
            else{
                temp.erase(found,1);
                n++;
            }
        }while(n < addresses[i].length());

        if (n == addresses[i].length())
            retval++;
        i++;
    }while(i < length);
    return retval;
}

int main()
{
    CIS14 cis14;
    string addresses[] = {"123C","123A","123 ADA"};
    string letterInventory = "AAAABCCC123456789";
    int length = sizeof(addresses)/sizeof(addresses[0]);
    cout << "Possible signs: " << cis14.getNumPossibleSigns(&letterInventory, addresses, length) << endl;
    return 0;
}
You've forgot to initialize i.
*facepalm

Thank you :)
Topic archived. No new replies allowed.