The point of the function is to see if the array (*Pointer points to it) has any 3's in it. If so, they should be deleted, the rest of the array has to be shoven forward and the endings which don't have any values by then turned into 0's.
The problem is that, once it gets to the end, the program thinks that it's done. So it closes.
By saying adding cin.ignore();, you're telling the program to wait for the user to enter something, then ignore whatever the user entered. This effectively makes your program a "Press Enter to exit" deal.
Note: You want to add cin.ignore(); just before your return 0; at the end of the int main() code block, not inside of your function there.
No, I mean I get an error , it has to shut down unexpectedly because of an error.
And the error happens in this piece of code.
There has to be something wrong with it...
I'm a newbie, so there's a good chance that I'm wrong, but I'm not sure if directly substracting an integer from a pointer like this works out well. The above code uses the decrement operator instead, to see if that might work.
I'm a newbie myself and am not sure if the following is a good way to do this... I already see how the logic can be improved and additional bounds checking be added, but hope it illustrates my approach well enough.
void CheckArray(int* pointer, constint length)
{
int number = 4;
int a = 0;
int b = 0;
// Find and compact all numbers found
while(a < length)
{
while (pointer[b] == number)
{
++b;
}
if (b < length)
{
pointer[a] = pointer[b];
++a;
++b;
}
elsebreak;
}
// Fill with zeroes
while (a < length)
{
pointer[a] = 0;
++a;
}
}
In your main function, you may use the array pointer directly CheckArray (arr, length). Not sure why you want to declare another pointer int* P_arr.