Extending $f: E\to\mathbb{R}$ continuous to $g:\mathbb{R}\to\mathbb{R}$ continuous The following is from Carothers' Real Analysis:

Let $E\subset \mathbb{R}$ be closed and let $f:E\to\mathbb{R}$ be continuous. Prove that $f$ extends to a continuous function on all of $\mathbb{R}$. That is, prove that there exists a continuous function $g:\mathbb{R}\to\mathbb{R}$ such that $f(x)=g(x)$ for $x\in E$.

Thoughts regarding the proof:
Let $E\subset \mathbb{R}$ be closed and suppose $f:E\to\mathbb{R}$ is continuous. Since $E$ is closed is given, I  suspect I will need to use a sequence of continuous functions which converges but I'm not sure how to incorporate this if this is indeed the case.
A hint to get me started on the proof would be appreciated. Thanks.
 A: Suppose $f\ge0$. Then one adapts Hausdorff proof of Tietze's extension theorem to this one variable case, by defining for $t\notin E$:
$$
\overline f(t)=\inf\Big\{f(s)+\frac{d(t,s)}{d(t,E)}-1: s\in E\Big\}
$$
where $d(t,s)=|t-s|$ and $d(t,E)=\inf\{|t-s|:s\in E\}$. That this indeed defines a continuous functions may require some though, but it's elementary. For arbitrary $f$ one has the usual decomposition $f=f^+-f^-$ into the positive and the negative parts of $f$.
A: hints since $E$ is closed in $\mathbb{R}$ so $E^c$ is open in $\mathbb{R}$...now we know that every open set in $\mathbb{R}$ is countable union of disjoint open intervals...let {$(a_i,b_i)$} s.t $i \in \mathbb{N}$ is the set of all disjoint open interval...then  for some $k \in \mathbb{N}$ we know the value of $f(a_k)$ and $f(b_k)$...so we can define a function $g_k$ in the interval $[a_k,b_k]$ s.t $f(a_k)=g(a_k)$ and $f(b_k)=g(b_k)$...and then then gluing up all such $g_k's$ and $f$ we can continuously extend the funtion...I think this much hint is enough..you can fill up all the details
