Distance between a point and a closed set is attained I know that if $X\subset\mathbb{R}$ and $a\in\mathbb{R}$, then
$$d(a,X)=\{\inf|x-a|,x\in X\}$$
I just proved that if $a\in\bar{X}$, then $d(a,X)=0$.
Now, I need to show that if $X$ is closed, then $\exists x_{0}\in X$ such that
$$d(a,X)=|a-x_{0}|$$
Well, since $X$ is closed, then $X=\bar{X}$. So, if $x_{0}\in X\Rightarrow x_{0}\in\bar{X}$. So 
$$d(x_{0},X)=\inf_{x\in X}|x-x_{0}|=0$$
I have
$$d(a,X)=\inf_{x\in X}|x-a|$$
so, using triangular inequality, I can show that
$$d(a,X)\leq\inf_{x\in X}|x-x_{0}|+\inf_{x\in X}|x_{0}-a|$$
And since $\inf_{x\in X}|x-x_{0}|=0$, then
$$d(a,X)\leq\inf_{x\in X}|x_{0}-a|$$
But, by the definition of $\inf$, we conclude that
$$d(a,X)=\inf_{x\in X}|x_{0}-a|$$
I want to know if my proof is correct.
 A: In my other answer I provided hints. Here I will give a complete proof that can be reviewed if one needs further explanation.
If $a \in X$ then
$\quad d(a,X)=\{\inf|x-a|,x\in X\} \le d(a,a) = 0$
So  $d(a,X)= 0$ and setting $x_0 = a$ works.
If $a \notin X$, then since $X$ is closed there exists an open interval $(b,c)$ such that
$\tag 1 a \in (b,c) \land (b,c) \cap X = \emptyset$
The union of open intervals with a nonempty intersection is always a (possibly extended) open interval. So there is a largest open interval $U$ containing $a$ that does not not intersect $X$. Since $X$ is assumed to be nonempty, there are only three possibilities:
$\tag 2 U = (s_0,t_0) \text{ with } s_0, t_0 \in \Bbb R$
$\tag 3 U = (u_0,+\infty) \text{ with } u_0 \in \Bbb R$
$\tag 4 U = (-\infty,v_0) \text{ with } v_0 \in \Bbb R$
Case 1: If $a - s_0 \le t_0 - a$ the take $x_0 = s_0$; else take $x_0 = t_0$.
Case 2: Take $x_0 = u_0$.
Case 3: Take $x_0 = v_0$.
A: To show that $x_0$ exist you have to define/construct it. Your argument is faulty since you never define/construct this number $x_0$.
Now as a 'warm-up' to tackling the problem, the OP should think about what happens when
$\tag 1 X = \{-1, +1\} \text{ and } a = 0$
Another exercise:
$\tag 2 X = \{-1, +1\} \text{ and } a = \frac{1}{2}$
Note that solving this problem for $\Bbb R$ is much easier than the corresponding result for complete metric spaces. The OP might want to use the real-analysis tag here.

Hint: For the OP's problem, there is a largest open interval $I$ containing $a$ that is disjoint from $X$. The open interval has the form
$\quad (x_1,x_2) \quad \text{ where NOT} \, \bigr[ x_1 = -\infty \land x_2 = +\infty \bigr ] \; \text{ since } X \ne \emptyset$
