My parents taught me to never give up.
My parents taught me never to give up.

As far as I know, the first sentence is right. But I'm not sure, and even if it really is, I couldn't explain why.

Could someone tell me which of these endings is right and why?

The infinitive "to X" should not be split by the presence of any other word or words between "to" and "X". This particular saying is so often used with the split infinitive, however, that I think it can be accepted with "to never give". There are many other cases where this prescriptive rule is relaxed.

Both ways are fine.
Students: We have free audio pronunciation exercises.
thank you:)
 CalifJim's reply was promoted to an answer.