This application has requested the runtime to terminate.

I have this code:

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
#include <iostream>
#include <deque>

using namespace std;

int main()
{

char iword[200];
string str_iword2;
int ilength=0;



cin.get(iword, sizeof(iword)); cin.ignore(1000,'\n');

char alfabet[]={'A', 'B', 'C', 'D','E','F', 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','Y','Z','a','b','c','c','d','e','f','g','h','i','j','k','0','l','m','n','o','p','q','r','s','t','u','v','x','y','z','0','1','2','3','4','5','6','7','8','9'};
    deque<char>alfabetet(alfabet, alfabet+sizeof(alfabet));

str_iword2=iword;

ilength=str_iword2.length();





int k=0;

for(int i=0; i<ilength; i++){

if(iword[i]==alfabetet.at(k)){iword[i]=char(65+1);}
else if(iword[i]!=alfabetet.at(k)){k++; i=i-1;}



}



cout<<iword;

    return 0;
}


And when I try to run the program it gives me this if I for example input "lol".
lol

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Process returned 3 (0x3)   execution time : 7.342 s
Press any key to continue.


I think it is because the else if, however I am not sure.
That is because k goes above alfabetet.length()-1. There is some bad logic in your code. What are you trying to do?

By the way,
line 17 could have been char alphabet[] = "ABCDEFGHIJ...";
to read input into an array and then make a string from it is a waste of time, since you can read into a string directly.
I am trying to check whether the first user input (iword[1, 2, etc]) is equal to the first instance in the deque alfabetet, which is A, and if not check whether iword[i] is equal to the second instance of alfabetet.
Topic archived. No new replies allowed.