Although there is few topics on scanf and line input reading, I was wondering on my code snippet why using it on a 2D array wasn't working is it an infinite loop even with the program ending correctly? Because it doesn't give an error nor it prints something on the output, if someone can enlighten me on what's wrong please?
using namespace std;
int main() {
int t, j = 0;
cin >> t;
int arr2d[t][t];
while (t--) {
for (int i=0; i <= t; i++) {
while (scanf("%d", &arr2d[i][j])) {
cout << arr2d[i][j];
j++;
}
}
}
return 0;
}
with the input being :
3
1 1 0
1 1 1
1 0 0
thank you!