# Approximating a continuous function by one with zero derivative

Let $f : \mathbb R \rightarrow \mathbb R$ be a continuous function. I am trying to prove that for each $\epsilon > 0$, there is a continuous function $g$ whose derivative exists and equals 0 almost everywhere such that $|f(x) - g(x)| < \epsilon$ for each $x \in \mathbb R$. So far, I've considered trying to use linear combinations of the cantor-lebesgue function (which is continuous and has zero derivative a.e.), but have not met with much success.

The singular functions are a subalgebra of $C[a,b]$, they contain the constant functions and they separate points, hence every continuous function on $[a,b]$ can be uniformly approximated by singular functions.
Approximate by [singular functions] $p_k(x)$ on each interval $[k,k+2]$, and put them together using a smooth partition of unity: if $\phi(x)$ is a smooth function with $\phi(x) = 0$ for $x \le 0$, $\phi(x) = 1$ for $x \ge 1$, and $0 \le \phi(x) \le 1$ for $0 \le x \le 1$, take $g(x) = \phi(x-k) p_k(x) + (1 - \phi(x-k)) p_{k-1}(x)$ for $k \le x \le k+1$.
Here is how to do this on $I=[0,1]$. $f$ is uniformly continuous on $I$, so find the $n$ so that if $|x-y|<1/n\;$, $|f(x)-f(y)|<\epsilon\;$. For $x\in[k/n,(k+1)/n]$ define $$g(x)=f(k/n)+C(nx-k)(f((k+1)/n)-f(k/n))$$ Where $C$ is the Cantor-Lebesgue function. This can then be repeated for other compact intervals.