Why i got "segmentation fault"?

how to solve segmentation fault error?

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
66
67
68
69
70
71
72
 #include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define PRINT "print"
#define QUATE "*"
char ch [15]; 
int main () {
    
    //Characters stream storage!
    ch [0] = 'p';
    ch [1] = 'r';
    ch [2] = 'i';
    ch [3] = 'n';
    ch [4] = 't';
    ch [5] = ' ';
    ch [6] = '"';
    ch [7] = 'h';
    ch [8] = 'a';
ch[9] = '"';
ch[10] = ' ';
ch[11] = 'E';
ch[12] = 'N'; 
ch[13] = 'D';
ch[14] = '/0';
    int strnum = 1;
    int chnum = 0; 
    string * token; //Tokens storage;
token = new string[strnum];
    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 = 1;
    int typnum ;
typnum = 1;
    string * type;
type = new string [typnum]; // Types numerization
    while (token[strnum] != "END"){
          if(token[strnum] == PRINT) {
                type[typnum] == "stmt";
                
                typnum++;
               
                strnum++;}
          else if(token[strnum] == QUATE) {
                type[typnum] == "spec";
                
                typnum++;
                
                strnum++;}
          else {
                type[typnum] == "txtdat";
               
                typnum++;
              
                strnum++;} 
          }  
                     */   
    cout <<"Your program is compiled!"; //If program processed corectly this line is shown
    cin.get ();                             
    return 0;
} 



Array indexes are zero based so token[1] is out of bounds.
Topic archived. No new replies allowed.