Let $f:R \to R$ be a continuous function that $\lim_{x\to +\infty}f(x)=\lim_{x \to -\infty}f(x)=0$ Let $f:R \to R$ be a continuous function that $\lim_{x\to +\infty}f(x)=\lim_{x \to -\infty}f(x)=0$. for every $\epsilon>0$ . show that ther is function $g:\mathbb{R}\to \mathbb{R}$ continuous with $\{x \in \mathbb{R}| g(x) \neq 0\}$ compact and $\sup_{x \in \mathbb{R}} |f(x)-g(x)|< \epsilon$
can you one help me with this question i have no idea to where to start
 A: Here is a slightly simplified solution:

For each $\epsilon > 0$, consider the function $\varphi_{\epsilon} : \mathbb{R} \to \mathbb{R}$ defined by
$$ \varphi_{\epsilon}(x) = \begin{cases}
x - \epsilon, & x > \epsilon \\
x + \epsilon, & x < -\epsilon \\
0, & -\epsilon \leq x \leq \epsilon.
\end{cases} $$
Then it is easy to check that $\varphi_{\epsilon}$ is continuous and satisfies $|\varphi_{\epsilon}(x) - x| \leq \epsilon$. Then consider
$$g = \varphi_{\epsilon/2} \circ f$$
and notice that $g$ is continuous and


*

*There exists $M > 0$ such that $|f(x)| < \frac{\epsilon}{2}$ whenever $|x| > M$. Since $$ \{ x : g(x) \neq 0 \} \subseteq \{ x : |f(x)| > \tfrac{\epsilon}{2} \} \subseteq [-M, M], $$ it follows that $g$ is compactly supported.

*$|f(x) - g(x)| = |f(x) - \varphi_{\epsilon/2}(f(x))| \leq \frac{\epsilon}{2} < \epsilon$ for all $x \in \mathbb{R}$.
Therefore $g$ is compactly supported and satisfies $\sup_{x\in\mathbb{R}} |f(x) - g(x)| < \epsilon$.
A: Well. Fix $\varepsilon>0$. Since
\begin{align}
\lim_{|x|\rightarrow \infty} f(x) = 0
\end{align}
then there exists $M>0$ such that when $|x|>M$ we have that $|f(x)|<\varepsilon$.
Let us now choose $g$ continuous such that $g\equiv f$ on $[-M, M]$, $g\equiv 0$ for all $|x|>2M$, and $|g|\leq |f|$ for all $ x \in [-2M, -M]\cup[M, 2M]$. 
Then we see that
\begin{align}
\sup_{x \in \mathbb{R}}| f(x)-g(x)| \leq &\ \sup_{x \in (-\infty, -M]}|f(x)-g(x)| + \sup_{x \in [-M, M]} |f(x)-g(x)|+\sup_{x \in [M, \infty)}|f(x)-g(x)|\\
\leq&\ \sup_{x \in (-\infty, -M]}|f(x)-g(x)|+\sup_{x \in [M, \infty)}|f(x)-g(x)|\\
\leq&\ 4\varepsilon.
\end{align}
A: The proposition is not true for all the $f$ that satisfies the hypothesis.
Let $f(x)=x$ for $x\in [-1,1]$ and $f(x)=\frac{1}{x}$ for $|x|>1$ (it is easy to see that $f$ satisfies the hypothesis).
Fix $0<\epsilon<\frac{1}{2}$ and suppose such $g$ exists. You have that $f(1)=1$ and $f(-1)=-1$ then
$$\frac{1}{2}<f(1)-\epsilon<g(1)$$
$$g(-1)<f(-1)+\epsilon<-\frac{1}{2}$$
Being $g$ continuous $\exists a\in (-1,1)$ such that $g(a)=0$.
Without loss of generality we suppose that $0\leq a$. Let $x_0=1$, we construct the sequence $x_n$ by choosing from $\forall n$ $x_{n+1}\in(a,x_n)$ such that
$$g(x_{n+1})=\frac{g(x_n)}{2}$$
Note that we can do that  for all $n$ because $g$ is continuous.
It is easy to see that both the sequences converge being $\forall n$
$$a<x_{n+1}<x_n$$  and 
$$g(x_n)=\frac{g(1)}{2^n}>0$$
So $x_n\rightarrow b\in [a,1)$ and $g(x_n)\rightarrow 0$.
Then $g(b)=0$ being $g$ continuous and, let $C=\{x\in\mathbb{R}|g(x)\neq0\}$, we have $\forall n$ $x_n\in C$, $x_n\rightarrow b$ and $b\notin C$, so $C$ cannot be compact.
As others said, you may have written the problem wrong. 
