I want to include several listings in my document with sections. I also want each listing to have labels like Listing 2.1 where 2 is section number and 1 is number of given listing within that section. So far I was able to produce this code:
\documentclass[a4paper]{article}
\usepackage{listings}
\lstset{frame=Trbl,numbers=left}
\begin{document}
\renewcommand{\thelstlisting}{\thesection.\arabic{lstlisting}}
\section{Introduction}
First listing is numbered properly.
\begin{lstlisting}[caption=First listing]
Lorem
Ipsum
\end{lstlisting}
Second is correct too.
\begin{lstlisting}[caption=Second listing]
Dolor sit Amet
\end{lstlisting}
So far, all listings in one section are correct.
\section{First problem}
When a new section begins, the counter doesn't get reset.
\begin{lstlisting}[caption=First listing in second section]
consectetur
adispicing
elit
\end{lstlisting}
\end{document}
But this produces the following result:

How can I reset the counter after the beginning of each section?

\numberwithin{lstlisting}{section}produces errorNo counter 'lstlisting' defined. \numberwithin{lstlisting}{section}– programagor Apr 16 '15 at 03:19