我在c中遇到了scanf()的问题
#include <stdio.h>
#include <stdlib.h>
void add(int *arr, int n);
int main() {
int arr[] = {};
add(arr, 4);
return 0;
}
void add(int *arr, int n){
for (int i = 0; i < n; i++){
printf("%d index is : ", i);
scanf("%d\n", &arr[i+1]);
}
}
i == 1之后,for循环无法正常工作...执行停止,然后我必须按一些字母并执行整个循环,没有值...
#include <stdio.h>
#include <stdlib.h>
void add(int *arr, int n);
int main() {
int arr[] = {};
add(arr, 4);
return 0;
}
void add(int *arr, int n){
for (int i = 0; i < n; i++){
printf("%d index is : ", i);
scanf("%d\n", &arr[i+1]);
}
}
the for loop doesn't work after the i == 1... the execution stops and then I have to press some alphabet and executes the whole for loop with no values...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在C和C ++中的此声明
无效。初始化列表不得为空。
取而代之的是,您可以在c
或
函数中写入,而不是在函数中
写入,
否则将访问数组之外的内存。
This declaration in C and in C++
is invalid. The initializer list shall not be empty.
Instead you could write in C
or
And within the function instead of
you have to write
Otherwise there will be an access to memory outside the array.