Why does $\int_a^b f(x)h'(x) \, \mathrm{d}x=0$ imply that $f$ is constant? As an assignment, I have to prove the following:

If $f(x)$ is a piecewise continuous function and $\int_a^b f(x)h'(x) \, \mathrm{d}x=0$ for all piecewise continuously differentiable $h(x)$ that satisfy $h(a)=h(b)=0$, then $f$ is constant on $[a,b]$.

The assignment also provides some hints:

Define $$c:=\frac{1}{b-a} \int_a^b f(x) \, \mathrm{d}x=\frac{1}{b-a} \sum_{i=1}^{m} \left ( \int_{x_{I-1}}^{x_i} f(x) \, \mathrm{d}x \right )$$ and use $$h(x)=\int_a^x f(s)-c \, \mathrm{d}s$$ Show that $$\int_a^b \left ( f(x)-c \right )h'(x) \, \mathrm{d}x=0$$ as well as $$\int_a^b \left ( f(x)-c \right )h'(x) \, \mathrm{d}x = \int_a^b \left ( f(x)-c \right )^2 \, \mathrm{d}x$$ and use this to conclude that $f(x)-c=0$ for all $x \in [a,b]$.

Now, from what I understand, $h(b)=0$:
$$h(x)=\int_a^b f(s)-c \, \mathrm{d}s=\int_a^b f(s) \, \mathrm{d}s-\left . cs \right |_{s=a}^b=(b-a)c-(cb-ca)=0$$
Obviously, $h(a)=0$ too.
What I don't understand, is how I'm supposed to manipulate $\int_a^b \left ( f(x)-c \right )h'(x) \, \mathrm{d}x$ to obtain $\int_a^b \left ( f(x)-c \right )^2 \, \mathrm{d}x$. I've tried numerous things (including integration by parts, which looks promising), but to no avail.
 A: Seems to me like a step to prove later the Euler-Lagrange equation in the calculus of variation.
Now let us assume
$\int_a^b f(x)h'(x) \, \mathrm{d}x=0$ for all piecewise continuously differentiable $h(x)$ that satisfy $h(a)=h(b)=0$
We now choose a special $h$ (having the properties above) to show that $f$ must be a constant and set
$$h(x)=\int_a^x f(s)-c \, \mathrm{d}s$$
Let us first show that $h(a) =0$. This is trivial. Then let us show that $h(b)=0$ :
$$h(b)=\int_a^b f(s)-c \, \mathrm{d}s=\int_a^b f(s) \, \mathrm{d}s-\left . cs \right |_{s=a}^b=\int_a^bf(s)ds-(b-a)c=\\
\int_a^bf(s)ds-\int_a^bf(s)ds=0$$
Now let us show that $\int_a^b (f(x)-c)^2 dx =0$:
$$\int_a^b (f(x)-c)^2 dx =\int_a^b (f(x)-c)h'(x) dx =\\
 \int_a^b f(x)h'(x) dx + \int_a^b -ch'(x) dx = \\
\int_a^b f(x)h'(x) dx -c (h(b)-h(a))$$
But we know from our assumption $\int_a^b f(x)h'(x) \, \mathrm{d}x=0$, so the first term vanishes and as $h(a)=h(b)=0$ so does the second term.
This results in 
$$\int_a^b (f(x)-c)^2 dx =0$$
As the integral of a nonnegative function is zero then the function $(f(x)-c)^2$ must be zero a.e as well, we have $f(x)=c \qquad x\in[a,b]$ 
A: First of all, assuming that $f$ has only a finite number of discontinuities, and noting that the integral is unaffected if we delete these points from $[a,b],$ we may assume without loss of generality that $f$ is continuous on all of $[a,b]$.
The second fact we will use is the following: if $f>0$ is continuous on $[a,b]$, and if $\int^b_a f(x)dx=0,$ then $f=0$ on $[a,b].$ To prove this, suppose it is false. Then there is an $x_0\in [a,b]$ such that $f(x_0)=\delta >0,$ and now the continuity of $f$ gives us a neighborhood $a<a'<x_0<b'<b$ such that $f(x)<\delta/2$ on $(a',b')$. This implies that $\int^b_a f(x)dx\ge \int^{b'}_{a'}f(x)dx\ge \frac{\delta (b'-a')}{2}>0$ which is a contradiction. 
Now, if we define $h(x)=\int^x_a (f(s)-c)ds$ where $c$ is as in the hint, then $h'(x)=f(x)-c$ and a direct substitution shows that $\int^b_a (f(x)-c)^2dx=0,$ and so by what we just proved, $(f(x)-c)^2=0$ and thus $f(x)=c$.
