For completeness, the example mentioned is the diagram
$$\require{AMScd}
\begin{CD}
@. \vdots @. \vdots @.\vdots\\
@. @VV{p}V @VV{p}V @VV{p}V\\
0 @>>> \mathbf{Z} @>{n}>> \mathbf{Z} @>>> \mathbf{Z}/(n) @>>> 0\\
@. @VV{p}V @VV{p}V @VV{p}V\\
0 @>>> \mathbf{Z} @>{n}>> \mathbf{Z} @>>> \mathbf{Z}/(n) @>>> 0\\
@. @VV{p}V @VV{p}V @VV{p}V\\
0 @>>> \mathbf{Z} @>{n}>> \mathbf{Z} @>>> \mathbf{Z}/(n) @>>> 0
\end{CD}$$
where $n$ and $p$ are coprime.
I think what might be confusing is that you have to take an inverse limit of the sequence of maps $\mathbf{Z} \overset{p}{\leftarrow} \mathbf{Z} \overset{p}{\leftarrow} \cdots$, which is different from the inverse limit of $\mathbf{Z} \overset{\mathrm{id}}{\leftarrow} \mathbf{Z} \overset{\mathrm{id}}{\leftarrow} \cdots$. In particular, you are right that the inverse limit of the latter will be $\mathbf{Z}$.
On the other hand,
$$\varprojlim \left(\mathbf{Z} \overset{p}{\leftarrow} \mathbf{Z} \overset{p}{\leftarrow} \cdots\right) = \left\{(a_0,a_1,\ldots,a_n,\ldots) \in \prod_{i=0}^\infty \mathbf{Z}\ \middle\vert\ p^{j-i}a_j = a_i\ \text{for all}\ j \ge i \right\} = 0$$
since if, say, $a_i \ne 0$, then it must be divisible by every power of $p$.
If you haven't seen the concrete description of the inverse limit, see for example Atiyah-Macdonald, p. 103. Thus, the inverse limit of the diagram above is
$$0 \longrightarrow 0 \longrightarrow 0 \longrightarrow \mathbf{Z}/(n) \longrightarrow 0$$
since the right vertical arrows are all isomorphisms; this sequence is obviously not exact.
Another example is the following from Atiyah-Macdonald, Exc. 10.2:
$$\require{AMScd}
\begin{CD}
@. \vdots @. \vdots @.\vdots\\
@. @VV{p}V @| @VVV\\
0 @>>> \mathbf{Z} @>{p^n}>> \mathbf{Z} @>>> \mathbf{Z}/p^n\mathbf{Z} @>>> 0\\
@. @VV{p}V @| @VVV\\
@. \vdots @. \vdots @.\vdots\\
@. @VV{p}V @| @VVV\\
0 @>>> \mathbf{Z} @>{p^2}>> \mathbf{Z} @>>> \mathbf{Z}/p^2\mathbf{Z} @>>> 0\\
@. @VV{p}V @| @VVV\\
0 @>>> \mathbf{Z} @>{p}>> \mathbf{Z} @>>> \mathbf{Z}/p\mathbf{Z} @>>> 0
\end{CD}$$
The inverse limit is
$$0 \longrightarrow 0 \longrightarrow \mathbf{Z} \longrightarrow \hat{\mathbf{Z}}_p \longrightarrow 0$$
where the left and middle columns are as above, and the right column is the example right above yours in Matsumura, p. 272; this sequence is not exact.