0

我已经阅读过有关类似问题的问题,但2D动态数组的问题已经在那里解决了。(有指针,但我想没有它们。)

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

int interseq ( int, int ); // interval sequence

int main()
{
    int arr[100] = { 75, 47, 64, 45, 67, 51, 55, 36, 63, 30,
                     39, 58, 55, 67, 70, 44, 46, 51, 51, 61,
                     50, 54, 49, 51, 52, 54, 64, 68, 45, 40,
                     48, 60, 55, 37, 36, 13, 62, 53, 37, 53,
                     52, 49, 37, 54, 69, 44, 53, 58, 77, 46,

                     44, 63, 57, 64, 28, 46, 50, 57, 42, 72,
                     12, 69, 52, 53, 77, 50, 45, 49, 49, 46,
                     28, 40, 65, 25, 45, 45, 62, 28, 39, 69,
                     52, 57, 39, 73, 37, 46, 38, 65, 49, 58,
                     63, 30, 51, 48, 47, 56, 48, 41, 30, 54 };

    printf("%d", interseq ( arr, diagArr) );

    return 0;
} 

/* User's function. Description: 'farr' is 'arr' and so on..  */
int interseq ( int farr, int fdiagArr)
{
   int min, i;

   for ( i = 0; i < 100; i++ )    // Finding the 'min' element.
      if ( farr[i+1] < farr[i] )  // there are 2 errors 
          min = farr[i];          // there is 1 error 
      else
          min = farr[i+1];        // there is 1 error 

return 1;
}

错误是一样的:

error: subscripted value is neither array nor pointer nor vector
4

2 回答 2

4

把它们变成指针:

int interseq(int *farr, int *fdiagArr)
                 ^          ^

我看不到diagArr您的代码中的内容,因此这部分是猜测。


正如评论中的 simonc 指出的那样,当i = 99,farr[i+1]将是非法的。你应该早点停下来或改变你的算法。

于 2013-04-11T10:29:08.970 回答
1

试试这个:

//int interseq ( int farr, int fdiagArr)
int interseq ( int farr[], int fdiagArr[])
于 2013-04-11T10:31:22.157 回答