I mentioned in a comment that you need more requirements on $f$ than just that is continuous. To give you a verbal explanation of the theorem I will assume it is non-decreasing. Then you can look at it as follows:
Since $f$ is non decreasing, $f(a)$ must be the minimum of $f$ over the interval, and $f(b)$ must be the maximum. Now it must be true that:
$$\int_a^b f(x)g(x)dx \geq f(a) \int_a^b g(x) dx$$
and
$$\int_a^b f(x)g(x)dx \leq f(b) \int_a^b g(x) dx$$
Now consider the function $F$ of $c$ given by
$$F(c) = f(a)\int_a^c g(x)dx + f(b)\int_c^b g(x) dx$$
This function must satisfy $F(b) \leq \int_a^b f(x)g(x)dx$ and also
$F(a) \geq \int_a^b f(x)g(x)dx$. Since it is continuous there must be a $c^*$ where equality holds. (By the intermediate value theorem).
So to put it in words. If you integrate a function $g$ from $a$ to $b$ and weight it by an increasing function $f$, then the weighted integral must be greater than the integral of $g$ times $f$'s min and less than the integral times $f$'s max. So there must be a point in between where $f$s min times some of $g$'s integral plus $f$'s max times the rest of $g$'s integral equals the total weighted integral.
The proof is correct, but can be made shorter and more accurate (there should be “there exists $c$” somewhere).
Consider $F(x)=\int_a^x f(t)\,dt$; then, by the fundamental theorem of calculus, $F'(x)=f(x)$, for every $x\in(a,b)$; moreover, $F(b)-F(a)=\int_a^b f(t)\,dt$.
Since $F$ is continuous over $[a,b]$ and differentiable over $(a,b)$, the mean value theorem applies and there exists $c\in(a,b)$ such that
$$
\frac{F(b)-F(a)}{b-a}=F'(c)
$$
that is,
$$
\int_a^b f(t)\,dt=(b-a)f(c)
$$
By the way, the proof can be given without mentioning the mean value theorem. Since $f$ is continuous over the interval $[a,b]$, it has a maximum value $M$ and a minimum value $m$. Then, by definition of integral and from $m\le f(t)\le M$, we have
$$
m(b-a)\le\int_a^b f(t)\,dt\le M(b-a)
$$
By the intermediate value theorem, there exists $c\in[a,b]$ such that
$$
f(c)=\frac{1}{b-a}\int_a^b f(t)\,dt
$$
This is somewhat less precise than the other version, because we cannot state, without further work, that $c$ can be chosen in $(a,b)$.
Best Answer
The formula did not come from any where, it is a definition of a new function $F(x)$ that will help during the proof. To avoid confusion i will denote this function as $H(x)$.
First of all The definition of the function $H(x)$ is $$ H(x)=\intop_a^xf(t)g(t)dt-\frac{A}{B}\intop_a^xg(t)dt $$ Where $A=\intop_a^bf(t)g(t)dt$ and $B=\intop_a^bg(t)dt$.
Because $g(x)>0$ and is continuous, then $\intop_a^bg(x)dx>0$, so $H(x)$ is well defined.
Assuming that $g(x),f(x)$ are continuous functions, from the Fundamental theorem of calculus it follows that $H(x)$ is a differentiable function. Notice that $$ \begin{align} H(a)=&\intop_a^af(x)g(x)dx-\frac{A}{B}\intop_a^ag(x)dx=0\\ H(b)=&\intop_a^bf(x)g(x)dx-\frac{\intop_a^bf(x)g(x)dx}{\intop_a^bg(x)dx}\intop_a^bg(x)dx=\\ =&\intop_a^bf(x)g(x)dx-\intop_a^bf(x)g(x)dx=0 \end{align} $$ So by Rolle's theorem there exists $c\in (a,b)$ such that $H'(c)=0$. From the Fundamental theorem of calculus the derivative is $$ 0=H'(c)=f(c)g(c)-\frac{A}{B}g(c) $$ And with a little arithmetic and because $g(c)\neq0$ we will get $$ A=f(c)\cdot B\,\Rightarrow\,\intop_a^bf(x)g(x)dx=f(c)\intop_a^bg(x)dx $$