\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{TimSch} \pdfinfo{ /Title (c-printf-scanf.pdf) /Creator (Cheatography) /Author (TimSch) /Subject (C - printf/scanf Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3280A} \definecolor{LightBackground}{HTML}{F9F1EF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{C - printf/scanf Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{TimSch} via \textcolor{DarkBackground}{\uline{cheatography.com/29480/cs/8653/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}TimSch \\ \uline{cheatography.com/timsch} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 24th July, 2016.\\ Updated 24th July, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{genereller Aufbau}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Parameter}} & {\bf{Beschreibung}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} * {\bf{NUR scanf}} & {\bf{optional}}, Zuweisung zum korrespondierenden Zeiger unterdrücken \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} Flags {\bf{NUR printf}} & {\bf{optional}}, bestimmt über numerische Vorzeichen, Dezimalpunkte, link/rechtsbündigkeit und anderes \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} Breite & {\bf{optional}}, minimal auszugebende Zeichenzahl. Der Rest wird mit Leerzeichen oder Nullen aufgefüllt. \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} F/N {\bf{NUR scanf}} & {\bf{optional}}, Gr{\"o}{\ss}e des Adress-Parameters \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} .Pr{\"a}zision & {\bf{optional}}, Angabe, wie pr{\"a}zise die Ausgabe sein soll \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{F/N/hh/h/l/ll/L} & {\bf{optional}}, Angabe der Gr{\"o}{\ss}e des Parameters \tn % Row Count 19 (+ 2) % Row 7 \SetRowColor{white} Typ & {\bf{obligatorisch}}, Angabe des Typs der auszugebenden Variablen \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{printf: }} \newline \% {[}Flags{]} {[}Breite{]} {[}.Pr{\"a}zision{]} {[}F/N/...{]} Typ \newline \newline {\bf{scanf: }} \newline \% {[}{\emph{{]} {[}Breite{]} {[}F|N{]}{[}hh|h|l|ll|L{]} Typ \newline {\bf{KEINE Leerzeichen! Sie dienen hier nur der Übersichtlichkeit!}} \newline \newline {\bf{Unterschiede der Pr{\"a}zision je nach Datentyp}} \newline }}Zeichenketten{\emph{: maximal auszugebende Zeichen \newline }}ganze Zahlen{\emph{: Minimalzahl von Zeichen \newline }}Flie{\ss}kommazahlen*: Maximalzahl der Nachkommastellen} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Besonderheiten von scanf}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Es dürfen nur Platzhalter und Leerzeichen verwendet werden} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Anstatt \%s kann auch \%{[}Suchzeichen{]} genutzt werden. \{\{nl\}\}{\bf{Beispiel: }}\{\{nl\}\} \%{[}abcd{]} erwartet nur Eingaben, die aus den Zeichen a, b, c, d bestehen. Bei allen anderen wird die Eingabe beendet.} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Wird als erstes Suchzeichen das Carret (\textasciicircum{}) verwendet, wird die Eingabe beendet, wenn eines der Suchzeichen eingegeben wird. \{\{nl\}\} {\bf{Beispiel: \{\{nl\}\}}} \%{[}\textasciicircum{}abcd{]} erwartet nur Eingaben, die {\bf{nicht}} aus den Zeichen a, b, c, d bestehen. Die Eingabe wird auch nicht bei wei{\ss}en Leerzeichen beendet.} \tn % Row Count 12 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Anstelle von Zeichenaufz{\"a}hlungen k{\"o}nnen auch Bereiche angegeben werden. \{\{nl\}\}{\bf{Beispiel:}} \{\{nl\}\}\% {[}0123456789{]} ist {\"a}quivalent mit \%{[}0-9{]}} \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Bei manchen Compilern kann bzw. muss bei der Formatangabe das s angehangen werden.} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Flags}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Flag}} & {\bf{Effekt}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} - & linksbündige Ausgabe \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} + & numerische Ausgabe immer mit Vorzeichen \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \{\{nobreak\}\}\textless{}Leerzeichen\textgreater{} & Positiven Zahlen wird ein Leerzeichen voran gestellt \tn % Row Count 7 (+ 3) % Row 4 \SetRowColor{LightBackground} \# & Alternative Darstellung \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Alternative Darstellungen: }} \newline {\bf{o:}} Es wird eine 0 vorangestellt. \newline {\bf{x/X:}} es wird ein 0x bzw. 0X vorangestellt. \newline {\bf{e/E/f}}: Es wird ein Dezimalpunkt ausgegeben, auch wenn es keine Nachkommastellen gibt. \newline {\bf{g/G:}} wie bei e/E, au{\ss}erdem werden folgende Nullen nicht unterdrückt. \newline \newline \# ist nicht erlaubt bei Typ d/i/u/c/s/p \newline + ist nicht erlaubt bei Typ c/s} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Breite}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Breite}} & {\bf{Ausgabe}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} n & (n = Dezimalzahl) - Es werden mind. n Zeichen ausgegeben und notfalls führende Leerzeichen genutzt. \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} 0n & (Dezimalzahl mit vorangestellter 0) - Es werden mind. n Zeichen ausgegeben und mit Nullen mit führenden Nullen aufgefüllt. \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} *n & Breite variabel bestimmbar \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Beispiel {\emph{n}} \newline `printf("\%}}d\textbackslash{}n", Breite, Wert);` //Breite muss int sein!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.88666 cm} x{2.09034 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Gr{\"o}{\ss}enangaben}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Gr{\"o}{\ss}enangabe}} & {\bf{Datentyp}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} hh\textasciicircum{}3\textasciicircum{} & char \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} h\textasciicircum{}1\textasciicircum{} & short \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} l & long \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} ll\textasciicircum{}3\textasciicircum{} & long long \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} L & long double \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} F\textasciicircum{}4\textasciicircum{} & Far (Zeiger) \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} N\textasciicircum{}4\textasciicircum{} & Near (Zeiger) \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{1: erst seit C89 \newline 2: erst seit C95 \newline 3: erst seit C99 \newline 4: Nur in 16-Bit Compilern \newline {\bf{Besonderheiten: }} \newline Bei cl ist der Datentyp wint\_t\textasciicircum{}2\textasciicircum{} \newline Bei sl ist der Datentyp wchar\_t* \textasciicircum{}3\textasciicircum{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Pr{\"a}zision}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Pr{\"a}zision}} & {\bf{Ausgabe}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} .0 & Standardausgabe - keine Ausgabe von Dezimalpunkt und Nachkommastellen für Flie{\ss}kommazahlen \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} .n & n = Dezimalzahl \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} .* & variable Pr{\"a}zision \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{Beispiel .}}{\emph{ \newline `printf("\%}}.{\emph{f\textbackslash{}n", Breite, Pr{\"a}zision, Wert);` //Breite und Pr{\"a}zision müssen int sein! \newline \newline {\bf{Unterschiede je nach Datentyp:}} \newline {\bf{gnaze Zahlen:}} Mindestanzahl von auszugebenden Ziffern \newline {\bf{Flie{\ss}kommazahlen (e/E/f/F):}} Ausgabe von }}n{\emph{ Nachkommastellen \newline {\bf{Flie{\ss}kommazahlen (g/G/a/A):}} Ausgabe von }}n* Ziffern \newline {\bf{Zeichenketten:}} maximale Anzahl von auszugebenden Zeichen} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Typ}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Typ}} & {\bf{Ausgabe}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} d~/~i & dezimaler Integer \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} u & vorzeichenloser dezimaler Integer \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} o & vorzeichenloser oktaler Integer \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} x~/~X & vorzeichenloser hexadezimaler Integer \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} f~/~F & dezimale Flie{\ss}kommazahl \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} e~/~E & dezimale Flie{\ss}kommazahl in Exponentendarstellung \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} g~/~G & wie e/E, aber in Kurzform \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} c & Zeichen \tn % Row Count 16 (+ 1) % Row 9 \SetRowColor{white} s & Zeichenkette bis zu einem Nullzeichen oder dem Erreichen der Pr{\"a}zision \tn % Row Count 19 (+ 3) % Row 10 \SetRowColor{LightBackground} p & Zeigeradresse \tn % Row Count 20 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}