Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
    #include <stdio.h>

    void main()
    {

        int arrsize;
        int randset;
        int max;
        int min;
        int arr[arrsize];
        int i, j;
        int swap;
        float mean;

        printf("Input array size:\n");
        scanf("%d", &arrsize);

        printf("Input random set:\n");
        scanf("%d", &randset);

        printf("Input maximum possible value:\n");
        scanf("%d", &max);

        printf("Input minimum possible value:\n");
        scanf("%d", &min);

        // SORTING //

        for (i = arrsize; i > 0; i--)
            for(j = 1 ; j < i ; j++)

// Subscripted value is neither array nor pointer vector  //

                **if(arrsize[j-1] > arrsize[j])**
                {
                    swap        = arr[j];
                    arr[j]      = arr[j-1];
                    arr[j-1]    = swap;
                }

        for (i=0; i < arrsize; i++)
            printf("%d", arr[i]);
        printf("\n\n");

        // MEAN //

        for(i = 0 ; i < arrsize ; i ++)
        {
//Subscripted value is neither array nor pointer vector //
            **mean += arrsize[i];**
            mean/= arrsize;

            printf("The mean is %.2lf\n\n", mean);
        }

        // MEDIAN //


        if(arrsize%2 == 0)
            {
                printf("The median is %.2lf", (float)(arr[arrsize/2 -1] + arr[arrsize/2]);
            }
            else
            {
                printf("The median is %d", arr [arrsize/2]);
                printf("\n\n\n");
            }

            printf("The midrange is %.2lf\n\n", (float)(arr[0] + arr[arrsize - 1] / 2);

    }


    void fillintarray(int myarray [], int arrsize, int min, int max, unsigned int randset)
    {
        int iter;
        srand (randset);
        for (iter =0 ; iter < arrsize ; iter++)
        {
            myarray[iter] = rand() % (max - min + 1) + min;
        }
    }


嗨,您好!我将出现错误的行用粗体标出,错误是
“下标值既不是数组也不是指针向量”
这是我的ComSci课程的练习:)非常感谢您的帮助!谢谢! :)

最佳答案

好吧,该错误消息具有很强的描述性-使用下标运算符int arrsize访问标量变量[],该变量只能应用于数组或指针类型。

您可能要检查第j-1个和第j个数组元素,应使用
if (arr[j-1] > arr[j])

关于c - 粗体字错误:“下标值既不是数组也不是指针 vector :(” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18032081/

10-11 23:16
查看更多