Let $M^{\prime}\xrightarrow{f}M\xrightarrow{g}M^{\prime\prime}\rightarrow 0 \DeclareMathOperator{\Hom}{Hom}$ be a sequence of $A$-modules and homomorphisms. I want to show that the sequence is exact if and only if for all $A$-modules $N$, the sequence $$0\rightarrow \Hom(M^{\prime\prime},N)\xrightarrow{\overline{g}} \Hom(M,N)\xrightarrow{\overline{f}} \Hom(M^{\prime},N)$$ is exact.
I have shown that $M^{\prime}\xrightarrow{f}M\xrightarrow{g}M^{\prime\prime}\rightarrow 0$ is exact implies $0\rightarrow \Hom(M^{\prime\prime},N)\xrightarrow{\overline{g}} \Hom(M,N)\xrightarrow{\overline{f}} \Hom(M^{\prime},N)$ is exact for all $A$-modules $N$.
Now suppose for all $A$-modules $N$, $0\rightarrow \Hom(M^{\prime\prime},N)\xrightarrow{\overline{g}} \Hom(M,N)\xrightarrow{\overline{f}} \Hom(M^{\prime},N)$ is exact. I want to show that $M^{\prime}\xrightarrow{f}M\xrightarrow{g}M^{\prime\prime}\rightarrow 0$ is exact. That is I have to show $g$ is onto and $\ker(g)=\operatorname{Image}(f)$. In Atiyah Macdonald's Commutative Algebra, it is written that since $\overline{g}$ is injective for all $A$-modules $N$, therefore $g$ is onto. But I could not understand it. Any explanation will be appreciated.