yulian
yulian

Reputation: 1627

'subscripted value is neither array nor pointer nor vector' error

I've read questions about similar problems, but 2D or dynamic arrays' problems has been solved there. (There are pointers, but I'd like to do it without them.)

#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;
}

The errors are the same:

error: subscripted value is neither array nor pointer nor vector

Upvotes: 0

Views: 1198

Answers (2)

cnicutar
cnicutar

Reputation: 182619

Make those into pointers:

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

I can't see what diagArr is in your code so that part is speculation.


As simonc points in the comments, when i = 99, farr[i+1] will be illegal. You should stop earlier or change your algorithm.

Upvotes: 4

Leo Chapiro
Leo Chapiro

Reputation: 13984

Try this:

//int interseq ( int farr, int fdiagArr)
int interseq ( int farr[], int fdiagArr[])

Upvotes: 1

Related Questions