André Henriques answer for a closed set $C$ can easily be improved to $C^\infty$ by considering $e^{1/(\alpha-x)+1/(x-\beta)}$ if $x\not\in C$ where $\alpha$ is the supremum of all elements $< x$ in $C$ (and $\alpha=-\infty$ if $C$ contains no elements which are $< x$) and where similarly $\beta$ is the infimum of all elements $> x$ in $C$ (respectively $\beta=\infty$ if $C$ contains no elements $> x$).