My program compiles and executes, but crashes when asking the user to enter the
ID: 3527973 • Letter: M
Question
My program compiles and executes, but crashes when asking the user to enter the values. I debugged my program and it says the error is at the cin line in the input function where pointer/offset notation is being done. Does anyone have any ideas on how to fix it? #include using namespace std; void alloc(int ****, int ****, int ****, int ****, int &, int &); void input(int ***[], int, int); int main() { int ****s = nullptr, ****t = nullptr, ****u = nullptr, ****v = nullptr, rows = 0, columns = 0; alloc(s, t, u, v, rows, columns); input(s, rows, columns); cin.ignore(); cout << endl << "Program Over" << endl; cout << "Press Enter to end --> "; cin.get(); return 0; } void alloc(int ****s, int ****t, int ****u, int ****v, int &rows, int &columns) { cout << "How many rows should the array have --> "; cin >> rows; cout << endl << "How many columns should the array have --> "; cin >> columns; s = new int***; *s = new int**; **s = new int*[rows]; t = s; v = u; u = s; for(int i = 0; i < rows; i++) { (**s)[i] = new int[columns]; } ****s = 0; } void input(int ***s[], int rows, int columns) { int count = 1, i, l; for(i = 0; i < rows; i++) { cout << endl << "For row " << count << " enter " << columns << " values separated by spaces --> "; count++; for(l = 0; l < columns; l++) { cin >> *(*(**s + i) + l); } } }Explanation / Answer
cin >> *(*(*s + i) + l);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.