# 13372 - Pointer Magic
## Brief
Make functions to change values of 2 malloced arrays. The functions he made are:
Swap, which takes in 2 characters and 2 integers and uses them for coordinates for the integers that needs to be swapped. (A B 1 2 means to swap the values of A[1] and B[2])
Switch, swaps all the values of array A and array B
Replace, which takes in 1 character and 2 integers, the first 2 are used for coordinates whereas the last integer is used for the new value.(A 1 100 means replace the value of A[1] to 100)
Stop, which stops the program and prints out the contents of both arrays.
## Input
integer M, the size of both arrays
M*2 number of integers which are the values of both arrays
A number of Commands:
Swap (2 characters and 2 integers)
Switch
Replace (1 character and 2 integers)
Stop (Stop the program and print the arrays)
## Output
The contents of both arrays followed by a newline
## Solution
```c=
//by Keith
#include<stdio.h>
#include <stdlib.h>
void Switch(int** X, int** Y){
int* C;
C = *X;
*X = *Y;
*Y = C;
return;
}
void Swap(int *X, int*Y){
int pos1, pos2, temp;
char temp1, temp2;
scanf(" %c %c %d %d", &temp1, &temp2, &pos1, &pos2);
int *C, *D;
if(temp1 == 'A') C = X;
else C = Y;
if(temp2 == 'A') D = X;
else D = Y;
temp = *(C + pos1);
*(C + pos1) = *(D + pos2);
*(D + pos2) = temp;
return;
}
void Replace(int *X, int*Y){
int pos, num;
char temp;
scanf(" %c %d %d", &temp, &pos, &num);
int *C;
if(temp == 'A') C = X;
else C = Y;
*(C + pos) = num;
return;
}
```