Hey all, this is a pretty basic program that will take a use submitted array and call functions to find the max,min and then a function to reverse the array. I have the first two functions written and working but I am having trouble with the reverse array function. The reverse function has to use pointers or else I won't get credit. Here is what I have so far, it is no working at the moment.

Guidelines "Implement a separate function to reverse the order of the array using call by reference. The input of this function should be two pointers (pointing to original array and reverse array). This reversed array should be printed in the main function"

Thanks for any and all help!!

-Ryan

#include <stdio.h> // includes the library for the c compiler/program
#include <math.h>


int findmax(int a[]);
int findmin(int a[]);
void swap(int* a[] , int* b[]);

main() //main function of the program
{ //

int basicarray[6];
int reversearray[6];
int i;
int choice;
int max;
int min;


for(i=0; i < 6; i++) {

    printf("Please eneter element %d",i);
    printf(" of the array\n");
    scanf("%d", &basicarray[i]);
}

printf("The array entered is %d %d %d %d %d %d\n\n" ,  basicarray[0] ,  basicarray[1] ,  
        basicarray[2] ,  basicarray[3] ,  basicarray[4] ,  basicarray[5]);

while(1) 
    {

printf("Please select from the menu below:\n\n");
printf("1. Find Maximum Integer in Array.\n");
printf("2. Find Minimum Integer in Array.\n");
printf("3. Reverse Order of the Array.\n");
printf("4. Exit.\n");
scanf("%d" , &choice);

switch (choice) {

case 1:
    max = findmax(basicarray);
    printf("Your option is: %d\n" , choice);
    printf("The Maximum Integer is %d\n" , max );
    break;

case 2:
    min = findmin(basicarray);
    printf("Your option is: %d\n" , choice);
    printf("The Minium Integer is %d\n" , min );
    break;

case 3:

for(i=0; i < 6; i++) {

    reversearray[i] = swap(&basicarray , &reversearray);
    printf("%d", reversearray[i]);
}

    break;

case 4:
    return 0;


default:
    printf("Choice doesn't exsist\n");
    break;


                }

system("pause"); /*pause to keep information on the screen*/


        }
}



int findmax(int a[]) 
{
    int max = a[0];
    int i;

    for (i=0; i < 6; i++) 
    {

        if(a[i] > max)
        {
        max = a[i];
        }
    }
    return (max);

}



int findmin(int a[]) 
{
    int min = a[0];
    int i;

    for (i=0; i < 6; i++) 
    {

        if(a[i] < min)
        {
        min = a[i];
        }
    }
    return (min);

}


void swap(int* a[] , int* b[])
    {
    int i = 0;
        for (i=0; i<6; i++) {

        b[i] = 

        }
}

Where did you

"Implement a separate function to reverse the order of the array using call by reference. The input of this function should be two pointers (pointing to original array and reverse array).

Without an attempt at this implementation, there's nothing to help with.

Ok so found some help from other programs but trying to fully understand it.

    case 3:
            revArray(basicarray);
            printf("Your option is: %d\n" , choice);
            printf("The reversed array is: ");
            p = basicarray; 
            while(p < basicarray + 6) 
                printf("%d ",*p++);
            printf("\n");

            break;







void revArray(int *p) 
{
    int a[6], i;    // declaring an array inside the function
    int *s = p;     // setting a pointer equal p which is the basicarray
    for(i = 6-1; i >=0; --i) 


 // this is counting down the array from 5-0 and this is setting a[5] what is in basicarray's 0 and so one right?

    {
        a[i] = *p++;
    }


    for(i = 0; i < 6; ++i) \\ no idea what this is doing?
    {
        *(s+i) = a[i];
    }
    return;
}

What happened to

The input of this function should be two pointers (pointing to original array and reverse array).

You need to start reading the assignment and doing what it asks for.

And why 6? Is that a magic number somehow?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.