Question: Suppose $f: [0,1] \rightarrow \mathbb{R}$ is continuous on $(0,1)$. Prove there is a sequence of step functions $\left\{f_{n}\right\}$ which converges pointwise to $f$ on $[0,1]$.
I saw the same question was asked here but I was still confused regarding the solution to the question.
I had attempted a solution but I now realize this solution is wrong:
Proof: Since $f$ is continuous on $(0,1)$, then for every $x \in (0,1)$ and for every $\epsilon>0$, there exists a $\delta(x)$ such that $|f(x)-f(y)|<\epsilon$ whenever $y \in (0,1)$ and $|y-x|<\delta(x)$. In particular, let $\epsilon_{n} = 1/2^{n}$ and let $\delta_{n}(x)$ be the corresponding $\delta$ which is guaranteed by the continuity of $f$. Fix a value of $n$ and choose a partition $x_{0}=0 < x_{1} < x_{2} < \ldots < x_{m} = 1$ such that $x_{i}-x_{i-1} < \delta_{n}(x)$. Let $f_{n}(x):= f(x_{i-1})$ for all $x \in (x_{i-1}, x_{i})$. Clearly $f_{n}(x)$ is a step function and hence $\left\{f_{n}\right\}$ is a sequence of step functions. Observe that $f_{n}(x)=f_{n}(x_{i-1})=f(x_{i-1})$. Finally, by the continuity of $f$ and by the fact that $x_{i}-x_{i-1} < \delta_{n}(x)$, we may conclude that \begin{align*} |f(x)-f_{n}(x)| \leq |f(x)-f(x_{i-1})| < \epsilon_{n} \end{align*} and so the sequence converges pointwise to $f$.
End of proof.
I was hoping someone can shed some light on the correct solution to this problem. Any hints would be appreciated. Thanks!