hello everyone,

So I was requsted coding a program which percieves two arrays and their size from the user,

the function supposes to create new array which contains all the similiar occurance of arrays in an increasing order the function need to return the size of new array with a pointer and of course the array itself, running tome should be nlogn+mlogn.

for exmaple two arrays A: 2 5 3 1 2 4 6 2 4 3 5 2

B: 7 5 2 5 8 1 2 5 9 2

and the new array is 1 2 2 2 5 5 and it's size is 6.

So what I did was to write two assists function one that percieves into them elements from the user the second sorts each of them with quick sort. The function itself create new array C and percieves into C numbers from the elements using merging and each time the size of C increases with realloc. My problem is that the program does not work I am trying to return the size of arrays and each time it returns me 2. Also I cannot print C when returning to the main,I will be very glad if someone can help me with that

here is the code

Code:#include<stdio.h> #include<stdlib.h> #include <assert.h> int *dyn_array_input(int num); void quicksort(int *arr, int first, int last); int *similiar_elements(int *A, int *B, int n, int m); void main() { int *A, *B, *C, n, m; printf("Please enter the size of array A n\n "); scanf("%d", &n); printf("Please enter the size of array B m\n "); scanf("%d", &m); printf("Please enter numbers into array A\n"); A = dyn_array_input(n); printf("Please enter numbers into array B\n"); B = dyn_array_input(m); C = similiar_elements(A, B, n, m); printf("The new array is %d",*C); for (int j = 0;j <*C;j++) { printf("%d", C[j]); } } int *dyn_array_input(int num) { int i = 0, *arr; arr = (int*)malloc(num * sizeof(int)); if (!arr) { printf("There is not enough space in the memory\n"); exit(1); } for (int i = 0;i < num;i++) { scanf("%d", &arr[i]); } return arr; } void quicksort(int *arr, int first, int last) { int i, j, pivot, temp; if (first<last) { pivot = first; i = first; j = last; while (i<j) { while (arr[i] <= arr[pivot] && i<last) i++; while (arr[j]>arr[pivot]) j--; if (i<j) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } temp = arr[pivot]; arr[pivot] = arr[j]; arr[j] = temp; quicksort(arr, first, j - 1); quicksort(arr, j + 1, last); } } int *similiar_elements(int *A, int *B, int n, int m) {\\This is the function quicksort(A,0,m); quicksort(B, 0,n); int *C, physical_size = 0, logical_size = 2, i = 0, j = 0, size_of_array=2; C = (int*)calloc(logical_size, sizeof(int)); while (i !=n && j != m) { if (logical_size == physical_size) { size_of_array *=2; C = (int*)realloc(C,logical_size*sizeof(int)); } if (A[i] == B[j]) { C[i] = A[i++]; C[i+1] = B[j++]; } if (A[i] > B[j]) { j++; } if (B[j] > A[i]) i++; } return &logical_size; }