Using a function to remove duplicates from an array in C++
I'm writing a program that has a user input integers into an array, calls a function that removes duplicates from that array, and then prints out the modified array. When I run it, it lets me input values into the array, but then gives me a "Segmentation fault" error message when I'm done inputing values. What am I doing wrong? Here is my code: #include <iostream> using namespace std; void rmDup(int array[], int& size) { for (int i = 0; i < size; i++) { for (int j = i + 1; j < size; j++) { if (array[i] == array[j]) { array[i - 1 ] = array[i]; size--; } } } } int main() { const int CAPACITY =