how to get rid of Illegal structure operation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sd99
    New Member
    • Feb 2016
    • 4

    how to get rid of Illegal structure operation?

    The question is to write C++ program using a function ( is_sorted() ) which takes a 1-D array and size as arguments, returns 1 if it is in ascending order, -1 if in descending order or else 0.
    I used int* a[10]; as i was getting an error with just int a[10] when calling the function, can anyone explain to me why i need int* and mostly how to get rid of the illegal structure operation?

    This is my code:
    #
    int is_sorted(int a[10], int n)
    {int ct1=0, ct2=0;
    for(int i=0;i<n;++i)
    {
    if(a[i]<=a[i+1])
    ct1++;
    else if(a[i]>=a[i+1])
    ct2++;
    }
    if(ct1==n)
    return 1;
    else if(ct2==n)
    return -1;
    else return 0;
    }

    void main()
    {int n;
    int* a[10];
    cin>>n; //the number of elements in an array
    for(int i=0;i<n;++i) //to enter the array
    cin>>a[i]; //the error
    is_sorted(a[10], n);
    getch();
    }
  • sd99
    New Member
    • Feb 2016
    • 4

    #2
    nvm got it
    corrections: (under main)
    int n, a[10];
    cin>>n;
    for(int i=0;i<n;++i)
    cin>>a[i];
    cout<<is_sorted (a,n)
    getch();
    }
    Last edited by sd99; Feb 7 '16, 03:17 PM. Reason: specifications (under main)

    Comment

    Working...