C语言for里面的scanf,为什么在语言C的嵌套for循环中跳过scanf()?

GoldMonkeyTMM

2

c

for-loop

scanf

我正在为类编写一个程序,要求用户输入二维数组的大小,然后让用户输入数组的值.这是我到目前为止的代码:

#include

int main(void)

{

// Setup

int N, M;

int row = 0, col = 0;

printf("\n");

printf("This program counts occurences of digits 0 through 9 in an NxM array.\n");

printf("Enter the size of the array (Row Column): ");

scanf(" %d %d", &N, &M);

int array[N][M];

// Array Input

for (row = 0; row < N; row++)

{

printf("Enter row %d: ", row);

for (col = 0; col < M; col++);

{

scanf(" %d", &array[row][col]);

}

}

printf("\n");

return 0;

}

在编译程序并输入信息时,我遇到的问题是,跳过第二个和所有后续的scanf()语句,或者在输入第一行后跳过整个第二个for循环.以下是输入输入的示例:

This program counts occurences of digits 0 through 9 in an NxM array.

Enter the size of the array (Row Column): 2 6

Enter row 0: 0 1 2 3 4 5

Enter row 1:

然后程序完全结束.我真的不知道为什么会被跳过.我已经尝试改变scanf()语句中有多少个空格,但无论我改变什么,都会出现同样的问题.我不确定我是否错过了我犯过的一些愚蠢的错误,或者是否存在更大的问题.我很擅长编码.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值