> vett_new[j]=vett[i];
j is your output index, which you need to increment each time you find a value to add to your array.
https://en.wikipedia.org/wiki/Debugger
For example, you would perhaps start with a breakpoint at line 36.
You run the code, type in what you want in your carico function.
When the program gets to the instruction corresponding to line 36, the debugger will take over (that's what breakpoints do).
The first thing you look at is the cont_p variable to see if it's a reasonable value.
Having decided it is, you could then single-step through the code to detect when what happens differs from what you expect.
> I tried to count the numbers but it still doesn't work.
But did you notice anything odd in what was wrong?
On visual inspection, it would seem that the
first number printed at line 47 would be the
last valid number in your array. This would be a big clue.