Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 通用函数输入阵列_C - Fatal编程技术网

C 通用函数输入阵列

C 通用函数输入阵列,c,C,我不知道这里出了什么问题。这应该是一个函数,用于从用户读取数组的大小,然后将其传递给函数以开始填充数组 #include <stdio.h> #include <stdlib.h> int input_array(int *start, int s_size); int main() { int arr_size; printf("Please enter the Size of your array: "); scanf("%d",&

我不知道这里出了什么问题。这应该是一个函数,用于从用户读取数组的大小,然后将其传递给函数以开始填充数组

#include <stdio.h>
#include <stdlib.h>

int input_array(int *start, int s_size);

int main()
{
    int arr_size;

    printf("Please enter the Size of your array: ");
    scanf("%d",&arr_size);

    int arr[arr_size];

    input_array(arr,arr_size);

    return 0;
}
int input_array(int *start, int s_size)
{
    static int counter=0;

    printf("Start fill your array with %d elements: \n\n",s_size);

    for(counter=0; counter<s_size; counter++)
    {
        printf("Input Element : ");
        scanf("%d",start[counter]);
        printf("\n");
    }
    return start[0];
}
#包括
#包括
int input_数组(int*start,int s_大小);
int main()
{
内部arr_大小;
printf(“请输入数组的大小:”);
scanf(“%d”和arr_大小);
int arr[arr_size];
输入_数组(arr,arr_大小);
返回0;
}
整数输入_数组(整数*开始,整数s_大小)
{
静态整数计数器=0;
printf(“开始用%d个元素填充数组:\n\n”,s\u大小);

对于(counter=0;counter函数中的
int-input\u数组(int*start,int-s\u size)
此语句

As
start
int*
-

scanf("%d",start[counter]);        // pass address of variable

您需要传递
start[counter]
的地址,因为它的类型是
int

我找到了这一行的答案

scanf("%d",start[counter]);
应该是

scanf("%d",&start[counter]);

and'&'运算符丢失了

lol,我也知道了,但无法想出正确的语法来获取间接索引int的地址:)@MartinJames-um,对不起,但我不太明白你想说什么:)我知道有什么问题,但不知道如何正确修复:(好的,我得到了错误,它在这行scanf(“%d”中),start[counter]);应该是scanf(“%d”,&start[counter]);@MartinJames传递
&start[counter]有什么问题
scanf
需要参数的
&
运算符的地址。这是您最喜欢的C编程初学者手册的第1章。在编译器的最高级别启用编译器警告,或者只启用
开始+计数器