我已经阅读过有关类似问题的问题,但 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
答案 0 :(得分:4)
将它们变成指针:
int interseq(int *farr, int *fdiagArr)
^ ^
我无法看到您的代码中有diagArr
,因此该部分是推测。
作为评论中的simonc点,当i = 99
时,farr[i+1]
将是非法的。您应该提前停止或更改算法。
答案 1 :(得分:1)
试试这个:
//int interseq ( int farr, int fdiagArr)
int interseq ( int farr[], int fdiagArr[])