# Problem inserting C snippet

I am trying to insert an snippet like this

But when I write

\usepackage{listings}
\lstset{language=C}
\begin{document}
\begin{lstlisting}
typedef double real_t; // Esto casi seguro necesita ser tipo doble
real_t UpdatePID(SPid * pid, real_t error, real_t position)
{
.
.
.
}
\end{lstlisting}
\end{document}


I get this out of margin. Is this a package problem or a problem in my page setup?

First line of LOG file:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6880 64-bit) (preloaded format=pdflatex 2018.11.27) 2 DEC 2018 22:42
entering extended mode


SOLVED:

I followed this link: Problems with the lstlisting environment (margin and white line)

Just add the option breaklines=true to \lstset like

\lstset{breaklines=true,language=C}


I added package showframe to visualize the typing area and margins.

The following MWE

\documentclass{article}

\usepackage{listings}
\usepackage{showframe} % <========= to visualize typing area and margins
\lstset{breaklines=true,language=C} % <=================================

\begin{document}
\begin{lstlisting}
typedef double real_t; // Esto casi seguro necesita ser tipo doble
real_t UpdatePID(SPid * pid, real_t error, real_t position)
{
.
.
.
}
\end{lstlisting}
\end{document}


gives you

• I added breaklines=true but still getting the same. My document class is book, does this affect? – Blue_Electronx Dec 3 '18 at 2:36
• Yes, I copied your code and I'm getting the same result. Well, my .text file is really long. I can't post the whole code here. But the main issue is just with the C snippet. I added the first line of my log file to my question. – Blue_Electronx Dec 3 '18 at 2:46
• @XavierPachecoPaulino well, then check your long code, search for definitions for listings and copy them into your code given in your answer. I`m sure you have used some option(s) resulting in your issue you did not show us ... – Mensch Dec 3 '18 at 2:55