We study the controllability problem for a distributed parameter system governed by the damped wave equation $$ u_{tt}-\frac{1}{\rho(x)}\frac{d}{dx}\left(p(x)\frac{du}{dx}\right)+ 2d(x)u_t+q(x)u=g(x)f(t), $$ where $x\in (0,a)$, with the boundary conditions $$ u(0)=0,\;\; (u_x+hu_t)(a)=0,\;\; h\in{\Bbb C}\cup\{\infty\}. $$ This equation describes the forced motion of a nonhomogeneous string subject to a viscous damping with the damping coefficient $d(x)$ and with damping (if Re $h>0$) or energy production (if Re $h<0$) at one end. (All results extend to the case when a similar condition is imposed at the other end as well.) The function $f(t)$ is considered as a control. Generalizing well-known results by D. Russell concerning the string with $d(x)=0$, we give necessary and sufficient conditions for exact unique controllability and approximate controllability of the system. Our proofs are based on recent results by M. Shubov concerning the spectral analysis of a class of nonselfadjoint operators and operator pencils generated by the above equation.