This is exercise 3.24 from "A User-Friendly Introduction to Lebesgue Measure and Integration" by Gail S. Nelson:
Let $f\in L^{p}[a,b]$ for $p\ge 1$. Given two real numbers, $A$ and $B$, and $\epsilon > 0$, show that there is a continuous function $g$ defined on $[a,b]$ with $g(a)=A$, $g(b)=B$, and $\|f-g\|_{p}<\epsilon$.
An approach that seems obvious is to use the fact that $C[a,b]$ is dense in $L^{p}[a,b]$, so that there is continuous function g defined on $[a+\delta,b-\delta]$, where $\delta>0$ is some small number, such that $\|f-g\|<\frac{\epsilon}{2}$ on given interval. Then, one would have to extend $g$ with linear segment between points $(a,A)$ and $(a+\delta,g(a+\delta))$, such that $L^{p}$ norm of the difference between $f$ and this linear segment, on the $[a,a+\delta]$ interval, is smaller than $\frac{\epsilon}{4}$; alike for the $[b-\delta,b]$ interval. The problem is: how to choose $\delta$ to assure that the $L^{p}$ norm of the mentioned difference is indeed smaller than $\frac{\epsilon}{4}$?
We divide the proof into two steps.
1) There is continuous function g defined $[a,b]$ such that $\|f-g\|_p<\frac{\epsilon}{2}$.
2) Let $h_{\delta}(x)$ be the continuous function in $[a,b]$, which is linear in $[a,a+\delta]$ and joins the points $(a,f(a))$, $(a+\delta, g(a+\delta)$, it is linear in $[b+\delta,b]$ and joins the points $(b,f(b))$, $(b-\delta, g(b-\delta))$, and it is equal to $g$ elsewhere. Then it follows that $g-h_{\delta}$ is a continuous function in $[a,b]$, which is uniformly (with respect to $\delta$) bounded by $M:=\max_{[a,b]}|g(x)|+|f(a)|+|f(b)|$. Moreover, as $\delta \to 0^+$, $$\|g-h_{\delta}\|^p_p\leq \int_{a}^{a+\delta}|g(x)-h_{\delta}(x)|^p dx +\int_{b-\delta}^{b}|g(x)-h_{\delta}(x)|^p dx\leq M^p\cdot 2\delta\to 0.$$
Finally we take a continuous function $h_{\delta}$ with $\delta>0$, such that $\|g-h_{\delta}\|_p<\frac{\epsilon}{2}$. Hence $$\|f-h_{\delta}\|_p\leq \|f-g\|_p+\|g-h_{\delta}\|_p<\epsilon.$$