A nontrivial everywhere continuous function with uncountably many roots?

This is my first post on SE, forgive any blunders.

I am looking for an example of a function $f:\mathbb{R} \to \mathbb{R}$ which is continuous everywhere but has uncountably many roots ($x$ such that $f(x) = 0$). I am not looking for trivial examples such as $f = 0$ for all $x$. This is not a homework problem. I'd prefer a nudge in the right direction rather than an explicit example.

Thanks!

Edit: Thanks all! I've constructed my example with your help.


The roots of a continuous function is always a closed subset of $\mathbb{R}$ : $\{0\}$ is closed, thus $f^{-1}(\{0\})$ is closed too.

If you have a closed set $S$, you can define a function $f : x \mapsto d(x,S)$, which is continuous and whose set of roots is exactly $S$ : you can make a continuous function have any closed set as its set of roots.

Therefore you only have to look for closed sets that are uncountable.


This could be interesting for you.


Even though you seem to be happy with the given answers, I can't resist pointing out the following construction which I already mentioned in this thread. If this example is already contained in one of the links provided in the other answer, I apologize for the duplication:

Choose a space-filling curve $c: \mathbb{R} \to \mathbb{R}^2$ and compose it with the projection $p$ to one of the coordinate axes. This gives you an example of a continuous and surjective function $f = p \circ c: \mathbb{R} \to \mathbb{R}$ all of whose pre-images are uncountable.


If $f(x)$ is the function then $E = \{ x \colon f(x) = 0 \} $ is a closed set. Do you know of a nontrivial, by your standards, closed set with uncountable many points? The complement of $E$ is open. Is there a way to describe the complement of $E$ so that it would be easy to construct the remainder of the function in such a way that the function was never $0$ on the complement of $E$.


Why not $f(x)=x+|x|$? Looks quite nontrivial to me.