I am doing an problem on Leetcode. The question is that given an array and a value, remove all instances of that value in place and return the new length.
Or you can read it [here](https://leetcode.com/problems/remove-element/):

```
int removeElement(int* nums, int numsSize, int val) {
    int *nums_copy; 
    int count = 0;
    int actual_count = 0;

    while (actual_count < numsSize) {

        if (nums[actual_count] != val) {
            nums_copy[count] = nums[actual_count];
            count++;
            nums_copy = realloc(nums_copy, sizeof(int)* count);
        } 
        actual_count++;
    }

    nums = nums_copy;
    return actual_count;
}

```

When I tried to test it with `[1, 2, 2, 3], 2`, the output is `[1, 2, 2, 3]` while the expected output is `[1, 3]`.