Hi every one,

include <stdio.h>

include <conio.h>

define SIZE 4

int
main(){
char Menu[SIZE] = {'A','B','C','D'};
int i;

for(i=0; i<(SIZE); i++){            // print the array elements
    printf("\t%c",Menu[i]);
}   
getch();

}

I want to swap the elements of the array for e.g. if I pass A and D or Menu[0], Menu[3], then the resulting array should be something like this when I print it:
D, B, C, A

I want to make use of pointers, I am new to C so don't know how to go about it......

Regards.

I want to make use of pointers, I am new to C so don't know how to go about it

Have you read about pointers? If not, get a good book, read about it. The forum lists a lot of good books on C. In case you still have doubts after reading it, you can post here.

Swap elements 1 and 3:

void swap1and3(void)
{
    char* p1 = &menu[1];
    char* p2 = &menu[3];
    char tmp;

    tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
}

So, a more generic offering:

void swapChars( char* p1, char* p2)
{
    char tmp;
    tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
}
This question has already been answered. Start a new discussion instead.