Show that $f$ is the $0$ element of $L^2 (\mathbb{R})$. Let $f\in L^2(\mathbb{R})$. Let $C^{\infty}_{c}(\mathbb{R})$ denote the set of compactly supported smooth functions on $\mathbb{R}$. Suppose that
$$\int_{\mathbb{R}}fg=0 $$ for all $g\in C^{\infty}_{c}(\mathbb{R})$
Show that $f$ is the $0$ element of $L^2 (\mathbb{R})$.
How should I proceed to solve this question. 
 A: $C_0^{\infty}(\mathbb{R})$ is dense in $L^2(\mathbb{R})$ thus exists a sequence $g_n \in C_0^{\infty}(\mathbb{R})$ such that $g_n \rightarrow f$ in $L^2(\mathbb{R})$.
Also $\int|g_n-f|^2=\int g_n^2+\int f^2 \Rightarrow \int g_n^2 \rightarrow -\int f^2$
Also $\int f^2 \leqslant \int |g_n-f|^2+ \int g_n^2$
Taking limits we have that $$2 \int f^2 \leqslant 0 \Rightarrow f^2=0$$  almost everywhere thus $f=0$ almost everywhere.
Now according to the comment below of @zhw there is an easier solution than the first one:
$$|\int g_nf-\int f^2| \leqslant \int|g_n-f||f| \leqslant \sqrt{\int|g_n-f|^2} \sqrt{\int|f|^2} \rightarrow 0$$
Thus $$0=\lim_{n \rightarrow \infty} \int g_nf=\int f^2$$
Thus $f=0$ almost everywhere.
A: Suppose $f\neq 0$. Then either $f^{-1}((0, \infty))$ or $f^{-1}((-\infty, 0))$ has positive measure- suppose WTLOG that $\mu(f^{-1}((0, \infty)))>0$. Now, by the continuity of measure $\lim_{n \rightarrow \infty} \mu(f^{-1}([1/n, \infty))) = \mu(f^{-1}((0, \infty)))>0$, hence we can find $N$ such that $\mu(f^{-1}([1/N, \infty)))>0$. Again, by the continuity of measure, $\lim_{m \rightarrow \infty} \mu(f^{-1}([1/N, \infty))\cap [-m,m])=\mu(f^{-1}([1/N, \infty)))>0$ hence we can find $M$ such that $\mu(f^{-1}([1/N, \infty))\cap [-M,M])>0$. Then setting $g=\mathcal{X}_{[-M,M]}$ we immideately see that $\int gf$ $d\mu>0$. This is the contrapositive of what you wanted to show.
