[Tex/LaTex] Cannot use a different directory for lstinputlisting

listingswindows

I'm having a bit of a problem. I'm trying to include source code in an appendix in latex. I use the following line in order to add the source code:

\lstinputlisting[language=C]{"C:\work\EA10080\trunk\Programming\Secondary_side\full_function\Submodules\ePWM.c"}

but I get the following error:

398 Undefined control sequence. \lst@inputpath "C:\work
\EA 10080\trunk \Programming \Secondary _… l.398 …ry_side\full_function\Submodules\ePWM.c"}

What am I doing wrong? I'm using the package listing, color and the document class is report.

Minimal working example:

\documentclass[12pt,a4paper]{report}

\usepackage{listings}
\usepackage{color}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\lstset{numbers=left,commentstyle=\color{mygreen},keywordstyle=\color{blue}}

\begin{document}

\begin{appendices}
\chapter{Source Code for PWM}
\label{sec:A}

\lstinputlisting[language=C]{"C:\work\EA10080\trunk\Programming\Secondary_side\full_function\Submodules\ePWM.c"}

\end{appendices}

\end{document}

Also, maybe I should mention that adding the source code "manually" (using \begin{listing} and then writing the code) works fine. It's much less practical though.

Best Answer

Changing \ to / should work!

\documentclass[12pt,a4paper]{report}

\usepackage{listings}
\usepackage{color}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\lstset{numbers=left,commentstyle=\color{mygreen},keywordstyle=\color{blue}}

\begin{document}

\begin{appendices}
\chapter{Source Code for PWM}
\label{sec:A}

\lstinputlisting[language=C]{"C:/work/EA10080/trunk/Programming/Secondary_side/full_function/Submodules/ePWM.c"}

\end{appendices}

\end{document}