so recently I have been working on a truth table generator which generates an equation for a logic statement. So, I decided to use a 2D array to make things seem more clean and neat. However, as I run this code(Don't worry, int main and other functions exist too, I am posting only this part since it is the one that causes an error):
int calculate(size_t length) {
int dimensionX = length + 2;
int dimensionY = 5;
calcArray = new string *[dimensionX];
for (int i = 0; i < dimensionX; i++) {
calcArray[i] = new string[dimensionY];
}
for (int i = 0; i < dimensionX; i++) {
delete[] calcArray[i];
delete[] calcArray;
}
return 0;
}
int count(string phrase, string calcArray[][]) {
string statement(phrase);
size_t ve = count(statement.begin(), statement.end(), 'A');
size_t yada = count(statement.begin(), statement.end(), 'V');
size_t ozel_yada = count(statement.begin(), statement.end(), 'XV');
size_t ok = count(statement.begin(), statement.end(), '->');
size_t cift_ok = count(statement.begin(), statement.end(), '<->');
size_t complete = ve + yada + ozel_yada + ok + cift_ok;
size_t column_number = complete;
return complete;
for (int i = 3; i < complete; i++) {
int andNum = phrase.find('A');
if (count (phrase.substr(andNum-3,6).begin(), phrase.substr(andNum - 3, 6).end(),'(') == 0){
string calcArray[0][i] = phrase.substr(andNum - 1, 4);
}
}
}
I get errors saying that:
An array may not have elements of this type( int count(string phrase, string calcArray[][])
cannot allocate an array of constant size 0 (string calcArray[0][i] = phrase.substr(andNum - 1, 4);)
An expression did not evaluate a constant (string calcArray[0][i] = phrase.substr(andNum - 1, 4);)
I would appreciate any help or explanation. Thanks