Dev c++ "microsoft error" with arrays?

My code is succesfully compiled, but then i run the program it throws microsoft error "don't send" button. What i'm doing wrong?

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
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
#include <ctype.h>
#include <fstream>
using namespace std;

int main () {
    /*SCANNER CHAPTER 1 - building tokens out of chars */
    char ch [100]; //Characters stream storage!
    ch [0] = 'p';
    ch [1] = 'r';
    ch [2] = 'i';
    ch [3] = 'n';
    ch [4] = 't';
    ch [5] = ' ';
    ch [6] = 'E';
    ch [7] = 'N';
    ch [8] = 'D';
    int strnum = 0;
    int chnum = 0; 
    string token [strnum]; //Tokens storage;
    while(token[strnum] != "END"){
                        if(isalpha(ch[chnum])) {
                                           token [strnum] += ch[chnum];
                                           chnum++;}
                        else if(ispunct(ch[chnum])) {
                                           token [strnum] += ch[chnum];
                                           chnum++;}
                        else if(isspace(ch[chnum])) {
                                           strnum++;
                                           chnum++;}                                
    }
    
    /*SCANNER CHAPTER 2 - Gruoping tokens into types */
    strnum = 0;
    int typnum = 0;
    int namenum = 0;
    string type[typnum]; // Types numerization
    string name[namenum]; // Names numerization
    while (token[strnum] != "END"){
          if(token[strnum] == "print") {
                type[typnum] == "stmt";
                name[namenum] == "print";
                typnum++;
                namenum++;
                strnum++;}
          else if(token[strnum] == "*") {
                type[typnum] == "spec";
                name[namenum] == "star";
                typnum++;
                namenum++;
                strnum++;}
          else {
                type[typnum] == "txtdat";
                name[namenum] == token[strnum];
                typnum++;
                namenum++;
                strnum++;} 
          }  
            string namex; 
          namex == name[namenum];              
    cout <<"Your program is compiled!"; //If program processed corectly this line is shown
    cin.get ();                             
    return 0;
}
It is obvious that the following code is invalid

1
2
3
    int strnum = 0;
    string token [strnum]; //Tokens storage;
    while(token[strnum] != "END"){


First of all the size of an array shall be a const expression according to the C++ Standard. Secondly your array has zero size. Thirdly you are trying to use uninitialized element of the array. So all this three statements are invalid.
Last edited on
thx Vlad!

Does my program is lexer? Is it correct?
I am sorry but I do not understand what it is doing.
Last edited on
Topic archived. No new replies allowed.