我试图用输入值填充矩阵。矩阵大小由第一行中的整数定义,然后我创建给定大小的数组并用输入中的值填充它。问题是我无法弄清楚为什么程序不这样做在第二个矩阵已满并且要求另一个输入值时停止。这是我的代码:
int main(int argc, char *argv[]){
int r1,r2,s1,s2;
//MATRIX 1.
if ((scanf("%d ",&r1)) == 0 || (scanf("%d", &s1)) == 0){
fprintf(stderr,"%s","Error: Chybny vstup!\n");
return 100;}
int matrix1[r1][s1];
for (int i = 0; i < r1; ++i){
for (int j = 0; j < s1; ++j){
if(!(scanf("%d ", &matrix1[i][j]))){
fprintf(stderr,"%s","Error: Chybny vstup!\n");
return 100;}
}
}
// OPERATOR
char operator;
if (!(scanf("%c", &operator) == 1)){
fprintf(stderr,"%s","Error: Chybny vstup!\n");
return 100;
}
//MATRIX 2.
if ((scanf("%d ",&r2)) == 0 || (scanf("%d", &s2)) == 0){
fprintf(stderr,"%s","Error: Chybny vstup!\n");
return 100;}
int matrix2[r2][s2];
for (int i = 0; i < r2; ++i){
for (int j = 0; j < s2; ++j){
if(!(scanf("%d ", &matrix2[i][j]))){
fprintf(stderr,"%s","Error: Chybny vstup!\n");
return 100;}
}
}
return 0;
}