How do I stop cocaine and not gain weight?

Sensibly. Cocaine kills! get help to get clean and put together the pieces of a healthy life---sleeping well, eating well, exercising regularly and socializing with friends who don't use.
Mutual support helps. Consider attending meetings of either or both Cocaine anonymous and overeaters anonymous. You will find solutions in both programs.