array allocates not wanted memory
Problem statement:
 Given a sequence of integers. For each group of 5 succesive elements
(1..5, 6..10 etc) find the minimum and put it in another array (the
length 1/5 from the initial array).
Use a function that gets a pointer to a sequence of 5 elements and a
pointer to an integer where it will store the result.


    void main()
    {
    int n1,i,z,k;
    int v[50],x[10];

    printf("length of array:");
    scanf("%d" , &n1);

    k = -1;

    readArray ( n1, v );
    for (i=0; i<=n1; i++)
    {    
        searchArray ( &k, &v[i], &x[k] );
    }
    writeArray ( k , x );
    }
v[i] is the initial array, x[k] the resulted array and k points where in x the result should be put.

    void searchArray ( int *k, int * v, int * x)
    {

    int i,z;
    bool dif;
    
    dif = false;
    z = z+1;
    if (v[i-1] == (v[i]-1))
    {
        dif = true;
        if ((dif == true) && (z == 4))
        {
            *k = *k+1;
            x[*k] = v[i-4];
            z = 0;
            if (v[i]+1 == v[i+1])
            {
                i = i+1;
            }
        } 
    }
    else if ( dif != true )
         {
             z = 0;
         }
    }
the problem: for an array from 1 to 10 the result is x[0] = 134513473 x[1] = 6 and if i look at x[-1] is 1. so instead of putting 1 in x[0] it puts it in x[-1] and x[0] return the memory adress.
array allocates not wanted memory
===

Problem statement:
 Given a sequence of integers. For each group of 5 succesive elements
(1..5, 6..10 etc) find the minimum and put it in another array (the
length 1/5 from the initial array).
Use a function that gets a pointer to a sequence of 5 elements and a
pointer to an integer where it will store the result.


    void main()
    {
    int n1,i,z,k;
    int v[50],x[10];

    printf("length of array:");
    scanf("%d" , &n1);

    k = -1;

    readArray ( n1, v );
    for (i=0; i<=n1; i++)
    {    
        searchArray ( &k, &v[i], &x[k] );
    }
    writeArray ( k , x );
    }
v[i] is the initial array, x[k] the resulted array and k points where in x the result should be put.

    void searchArray ( int *k, int * v, int * x)
    {

    int i,z;
    bool dif;
    
    dif = false;
    z = z+1;
    if (v[i-1] == (v[i]-1))
    {
        dif = true;
        if ((dif == true) && (z == 4))
        {
            *k = *k+1;
            x[*k] = v[i-4];
            z = 0;
            if (v[i]+1 == v[i+1])
            {
                i = i+1;
            }
        } 
    }
    else if ( dif != true )
         {
             z = 0;
         }
    }
the problem: for an array from 1 to 10 the result is x[0] = 134513473 x[1] = 6 and if i look at x[-1] is 1. so instead of putting 1 in x[0] it puts it in x[-1] and x[0] return the memory adress.