I am using the following settings to format my code blocks:
% xxxxxxxxxxxxxxxxxxxxxxxxx Code Snippet STARTS xxxxxxxxxxxxxxxxxxxxxx
\lstset{
language=C, % choose the language of the code
stepnumber=1, % the step between two line-numbers. If it's 1, each line will be numbered
% numbersep=5pt, % how far the line-numbers are from the code
% backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
tabsize=4, % sets default tabsize to 2 spaces
captionpos=t, % sets the caption-position to top
breaklines=true, % sets automatic line breaking
breakatwhitespace=true, % sets if automatic breaks should only happen at whitespace
% title=\lstname, % show the filename of files included with \lstinputlisting;
identifierstyle=\color{identifierColor},
caption={Array of Pointers to Strings},
frame=lrtb,
keywordstyle=\color{purple}, % keyword style
commentstyle=\color{blue}, % comment style
stringstyle=\color{violet}, % string literal style
belowcaptionskip = 0.2in, % Space below caption
abovecaptionskip = 0.2in, % Space above caption
}
\begin{lstlisting}
int main()
{
char *strings[] = {
"String1",
"String2",
"String3",
"String4"
};
char *ptr_swap; /* A temporary pointer to swap strings */
/* Swap "String2" with 'String3' */
ptr_swap = names [1];
names [1] = names [2];
names [2] = ptr_swap;
return 0;
}
% xxxxxxxxxxxxxxxxxxxxxxxxx Code Snippet ENDS xxxxxxxxxxxxxxxxxxxxxx
The Output is as follows:
My Question is:
The C Keywords (like: int, char) are NOT differently colored than the rest of the code.
I want to obtain a more beautiful output (like in professional books).
Please guide me on this issue.
Thanks.
int
,char
andreturn
have indeed a different shade on my monitor. They are red-purple-ish, while variable names are red-orange-ish. Do you have a slight form of daltonism maybe? (no, I am not trolling, I am serious).Pascal
days:identifierstyle=\color{black}
,keywordstyle={\color{blue}\bf}
,commentstyle=\color{gray}
,stringstyle=\color{green!40!gray}
.