Mam problem ze zdefiniowaniem tablicy o rozmiarze pobieranym z wejścia. W poprzednich programach ten sposób działał, jednak tutaj dla count > 2 (np. 4) program zwraca błąd Segmentation fault. Kod wygląda mniej więcej tak:
int count;
cin >> count;
int towerSize[count];
...a w orginale:
int debug = 1;
if(debug)cout<<"Start\n";
if(debug)cout<<"Init count";
int count;
if(debug)cout<<" - \033[32mOK\033[0m\nGet count:\n > ";
cin >> count;
if(debug)cout<<" - \033[32mOK\033[0m count = "<<count<<"\nInit next vars: ";
int towerSize[count];
if(debug)cout<<"towerSize, ";
int i, j;
if(debug)cout<<"i, j, ";
int tower[count][1000000];
if(debug)cout<<"tower, ";
int towerMax=0;
if(debug)cout<<"towerMax; \033[32mOK\033[0m";
Przykłady działania:
arrviasto@MajesticUbuntu: ... $ ./wie.e
Start
Init count - OK
Get count:2
- OK count = 2
Init next vars: towerSize, i, j, tower, towerMax; OK^C
arrviasto@MajesticUbuntu: ... $ ./wie.e
Start
Init count - OK
Get count:3
- OK count = 3
Segmentation fault
arrviasto@MajesticUbuntu: ... $ ./wie.e
Start
Init count - OK
Get count:4
- OK count = 4
Segmentation fault