Proving functions are injective and surjective I am having trouble with the following problem:
For nonempty sets $A$ and $B$ and functions $f:A \rightarrow B$ and $g:B \rightarrow A$ suppose that $g\circ f=i_A$, the identity function of $A$. Prove that $f$ is injective and $g$ is surjective.
Work: Since $g\circ f=i_A$, then $g\circ f:A\rightarrow A$. 
After this point, I don't know how to proceed. 

If $f$ weren't injective then $f(x_1)= f(x_2)$ for some $x_1\neq x_2$ in $A$.
So that $x_1=g\circ f\;(x_1)=g\circ f\;(x_2)=x_2$, since $g\circ f$ is the identity function on $A$.
Similarly, if $g$ weren't surjective then for some $a\in A$ there is no $b\in B$ such that $g(b)=a$. But $g\circ f\;(a)=a$.
