\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{aaa} \pdfinfo{ /Title (c-programming.pdf) /Creator (Cheatography) /Author (aaa) /Subject (C Programming 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}{FF8C19} \definecolor{LightBackground}{HTML}{FFF7F0} \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 Programming Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{aaa} via \textcolor{DarkBackground}{\uline{cheatography.com/27686/cs/8089/}}} \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}aaa \\ \uline{cheatography.com/aaa} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 13th May, 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*}{2} \begin{tabularx}{8.4cm}{x{2.508 cm} x{2.584 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Data types and Variables}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}\{\{bb\}\}{\bf{Arrays}} & ~\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `\textless{}type\textgreater{}`\{\{nobreak\}\} & \{\{nobreak\}\}`\textless{}array\_name\textgreater{}{[}\textless{}index\textgreater{}{]}` & `= expression`\{\{nobreak\}\} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}\{\{bb\}\}{\bf{Pointers}} & ~\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} `\textless{}type\textgreater{} ` & `{\bf{*p}}` & Declares {\emph{p}} a pointer. \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} `p =` & `{\bf{\&var}}` & Declares pointer to the variable {\emph{var}}. \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} `\textless{}type\textgreater{} ` & `{\bf{**pp}}` & Declares {\emph{pp}} a pointer to a pointer. \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} `pp =` & `{\bf{\&p}}` & Declares pointer to the pointer {\emph{p}}. \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} \{\{nobreak\}\}\{\{bb\}\}{\bf{Structures}} & ~\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 23 (+ 3) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{`struct tag\_name \{ }}\{\{nl\}\}~ ~\textless{}type\textgreater{} \textless{}element1\textgreater{}; \{\{nl\}\}~ ~\textless{}type\textgreater{} \textless{}element2\textgreater{}; \{\{nl\}\}{\bf{\}}}` & Structures allow a programmer to have a collection of elements of different types representing something. & \tn % Row Count 33 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Formatting}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Escape Characters}}\{\{nobreak\}\}\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `{\bf{\textbackslash{}a}}` & Alert bell \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} `{\bf{\textbackslash{}b}}` & Backspace \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} `{\bf{\textbackslash{}n}}` & Newline \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} `{\emph{*\textbackslash{}*}}` & Backslash \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} `{\bf{\textbackslash{}"}}` & Double quote \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} `{\bf{\textbackslash{}?}}` & Question Mark \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} {\bf{Conversion Specifiers}}\{\{nobreak\}\}\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 11 (+ 3) % Row 8 \SetRowColor{LightBackground} `{\bf{\%c}}` & char \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} `{\bf{\%s}}` & string \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} `{\bf{\%d}}` & int \tn % Row Count 14 (+ 1) % Row 11 \SetRowColor{white} `{\bf{\%u}}` & unsigned int \tn % Row Count 15 (+ 1) % Row 12 \SetRowColor{LightBackground} `{\bf{\%ld}}` & long int \tn % Row Count 16 (+ 1) % Row 13 \SetRowColor{white} `{\bf{\%o}}` & octal \tn % Row Count 17 (+ 1) % Row 14 \SetRowColor{LightBackground} `{\bf{\%x}}` & hexadecimal \tn % Row Count 18 (+ 1) % Row 15 \SetRowColor{white} `{\bf{\%d}}` & double \tn % Row Count 19 (+ 1) % Row 16 \SetRowColor{LightBackground} \{\{bb\}\}Formatted I/O & ~\{\{bb\}\} \tn % Row Count 20 (+ 1) % Row 17 \SetRowColor{white} `{\bf{\%5.2f}}` & Width of the printed field. \{\{nl\}\}ie. `'123.5'` becomes `'~~123.50'`. \tn % Row Count 24 (+ 4) % Row 18 \SetRowColor{LightBackground} `{\bf{\%04d}}` & Fills unused space with zeros.\{\{nl\}\}ie. `21` becomes `0021`. \tn % Row Count 27 (+ 3) % Row 19 \SetRowColor{white} `{\bf{\%-f}}` & Aligns the output to the right. \tn % Row Count 29 (+ 2) % Row 20 \SetRowColor{LightBackground} `{\bf{\%{[}aeiou{]}}}` & Remove all characters but vowels. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Formatting (cont)}} \tn % Row 21 \SetRowColor{LightBackground} `{\bf{\%{[}\textasciicircum{}aeiou{]}}}` & Remove all the vowels. \tn % Row Count 2 (+ 2) % Row 22 \SetRowColor{white} `{\bf{\%d*\%d*\%d}}` & Eliminate unnecessary characters. \{\{nl\}\}ie. `1/1/2001` can be stored in three integers as `1`,`1` and `2001`. \tn % Row Count 8 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{\{\{fa-hand-o-right\}\} Example:}}\{\{nl\}\}`int integer = 1; \{\{nl\}\}printf("This is an integer: \%d", integer);`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{~}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Dynamic memory allocation}} \tn % Row 0 \SetRowColor{LightBackground} `void* {\bf{malloc(}}int size{\bf{)}}` & Allocates {\emph{size}} contiguous bytes of memory and returns a void pointer to the first byte allocated. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} `void* {\bf{calloc(}}int items, int size{\bf{)}}` & Allocates {\emph{iitems x size}} contiguous {\bf{cleared}} (set to 0) bytes of memory and returns a void pointer to the first byte allocated. \tn % Row Count 12 (+ 7) % Row 2 \SetRowColor{LightBackground} `void* {\bf{calloc(}}void* ptr, int new\_size{\bf{)}}` & Resizes allocated memory being pointed at by {\emph{ptr}} to be {\emph{size}} bytes and returns a void pointer to the first byte allocated. \tn % Row Count 19 (+ 7) % Row 3 \SetRowColor{white} `void {\bf{free(}} void* ptr{\bf{)}}` & Frees memory that is pointed at by {\emph{ptr}}. \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Linked lists}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}`struct node \{ int x;\{\{nl\}\}~~struct node* next;\{\{nl\}\}\};\{\{nl\}\}...\{\{nl\}\}struct node* head; ` & A structure pointing to other nodes.\{\{nl\}\}The first element is assigned to a pointer {\emph{head}}. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \{\{nobreak\}\}`struct node* ptr = head;\{\{nl\}\}while(ptr!= NULL)\{\{\{nl\}\}~~printf("\%d\textbackslash{}n", ptr-\textgreater{}x);\{\{nl\}\}~~ptr = ptr-\textgreater{}next;\{\{nl\}\}\}` & Traversing the list. \tn % Row Count 14 (+ 8) % Row 2 \SetRowColor{LightBackground} `\{\{nobreak\}\}while(head != NULL)\{\{\{nl\}\}~~ptr = head-\textgreater{}next;\{\{\{nl\}\}~~free(head);\{\{\{nl\}\}~~head = ptr;\{\{\{nl\}\}\}` & Deleting an element.\{\{nl\}\}\{\{fa-exclamation\}\}You need to free the elements in the right order. \tn % Row Count 21 (+ 7) % Row 3 \SetRowColor{white} \{\{nobreak\}\}`if(ptr == NULL)\{\{\{nl\}\}~~ptr = \seqsplit{malloc(sizeof(struct} node));\{\{nl\}\}~~ptr-\textgreater{}x = 4;\{\{nl\}\}~~ptr-\textgreater{}next = NULL;\{\{nl\}\}~~head = ptr;\{\{nl\}\}\}` & Adding an element.\{\{nl\}\}\{\{fa-exclamation\}\}You need to cycle to the end first. \tn % Row Count 31 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{A linked list is a dynamic data structure consisting of a {\bf{sequence of records}} where each element contains a {\bf{link to the next record}}. They can be linked {\bf{singularly}}, {\bf{doubly}} or {\bf{circularly}}. \{\{nl\}\}\{\{fa-check-square-o\}\} Every node has a payloead and a link to the next node. \{\{nl\}\}\{\{fa-check-square-o\}\} The end is indicated by a {\emph{NULL}} pointer. \{\{nl\}\}\{\{fa-check-square-o\}\} It needs a pointer to the first item in the list.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Basics of C}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{General functions}}\{\{bb\}\} & ~\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `char` & \{\{nobreak\}\}{\bf{`getchar()`}} & \{\{nobreak\}\}Obtains character from input stream \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} `int` & \{\{nobreak\}\}{\bf{`sizeof(}}void var{\bf{)`}} & \{\{nobreak\}\}Returns size in bytes of \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} \{\{nobreak\}\}{\bf{Mathematical functions}}\{\{bb\}\} & ~\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} `double` & `{\bf{sqrt(}}double x{\bf{)`}} & Square root of x \tn % Row Count 16 (+ 2) % Row 5 \SetRowColor{white} `double` & \{\{nobreak\}\}`{\bf{pow(}}double x, double y{\bf{)}}` & x raised to the power of y \tn % Row Count 20 (+ 4) % Row 6 \SetRowColor{LightBackground} `double` & `{\bf{abs(}}double x{\bf{)}}` & Absolute value of x \tn % Row Count 22 (+ 2) % Row 7 \SetRowColor{white} `double` & `{\bf{ceil(}}double x{\bf{)}}` & Rounds x to the smallest int no less than x \tn % Row Count 26 (+ 4) % Row 8 \SetRowColor{LightBackground} `double` & `{\bf{floor(}}double x{\bf{)}}` & Rounds x to the largest int not greater than x \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Basics of C (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Command line Arguments}}\{\{bb\}\} & ~\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 4 (+ 4) % Row 10 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{`int main ({\bf{int argc, char* argv{[}{]}}})\{ \{\{nl\}\} ~ ~ /*code*/\{\{nl\}\} \}`} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{`int main ({\bf{int argc, char* argv{[}{]}}})\{ \{\{nl\}\} ~ ~ /*code*/\{\{nl\}\} \}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pre-processing}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Pre-processor identifiers}}\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `{\bf{\_LINE\_}}` & Current line being compiled. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `{\bf{\_FILE\_}}` & Name of source file. \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} `{\bf{\_DATE\_}}` & Date of compilation (mm dd yy). \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} `{\bf{\_TIME\_}}` & Time of compilation (hh:mm:ss) \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \{\{nobreak\}\}{\bf{Macros}}\{\{bb\}\} & ~\{\{bb\}\} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} `{\bf{\#include \textless{}some\_lib.h\textgreater{}}}` & The contents of {\emph{`\#include`}} are read and merged into the file. \tn % Row Count 16 (+ 4) % Row 7 \SetRowColor{white} `{\bf{\#define VAR VALUE}}` & Define a variable. \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} `{\bf{\#ifdef DEBUG \{\{nl\}\}~~{\emph{expression}} \{\{nl\}\}\#endif}}` & Define a variable. \tn % Row Count 22 (+ 4) % Row 9 \SetRowColor{white} `{\bf{\#ifdef DEBUG \{\{nl\}\}~~{\emph{expression}} \{\{nl\}\}\#endif}}` & Conditional compilation can be turned on by both setting `{\emph{\#define DEBUG 1}}` or by `-D` in the command line. \tn % Row Count 28 (+ 6) % Row 10 \SetRowColor{LightBackground} `{\bf{\#ifdef {\emph{condition}} \{\{nl\}\}\{\{nobreak\}\}~~\#error "Error message" \{\{nl\}\}\#endif}}` & Prints text as error message. \tn % Row Count 33 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-graduation-cap\}\} Function-like macros are {\bf{pre-processed}} and have {\bf{no type checking}} and are {\bf{not checked for compilation errors}}, but are {\bf{executed faster}} than normal C functions.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.76 cm} x{3.42 cm} x{3.42 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Strings}} \tn % Row 0 \SetRowColor{LightBackground} `int` & {\bf{`\{\{nobreak\}\}printf(}}char out{\bf{)`}}\{\{nobreak\}\} & Prints {\bf{formatted}}output to stdout \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `int` & `{\bf{scanf(}}char *input{\bf{)}}`\{\{nobreak\}\} & Reads {\bf{formatted}} input from stdin \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} `int` & `{\bf{puts(}}char *input{\bf{)}}`\{\{nobreak\}\} & Writes a string to stdout up to but {\bf{not including the null character}}. A {\bf{newline character is appended}} to the output. \tn % Row Count 13 (+ 7) % Row 3 \SetRowColor{white} \seqsplit{`char*`} & `{\bf{fgets(}}char *str, int n, FILE *stream{\bf{)}}`\{\{nobreak\}\} & Reads a line from the specified stream and stores it into the string pointed to by str. It stops when either {\bf{(n-1)}} characters are read, the {\bf{newline character}} is read, or the {\bf{end-of-file}} is reached, whichever comes first. \tn % Row Count 26 (+ 13) % Row 4 \SetRowColor{LightBackground} \seqsplit{`char*`} & \{\{nobreak\}\}`{\bf{strcpy(}}char dest, char src{\bf{)}}` & Pass a string to another string variable. \tn % Row Count 29 (+ 3) % Row 5 \SetRowColor{white} `int` & `{\bf{strcat(}}char *dest, char *src{\bf{)}}`\{\{nobreak\}\} & Appends the string pointed to by src to the end of the string pointed to by dest \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{p{0.76 cm} x{3.42 cm} x{3.42 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Strings (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \seqsplit{`char*`} & `{\bf{strlen(const char *str)}}`\{\{nobreak\}\} & Computes the length of the string str up to, but not including the terminating null character. \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{b}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Sockets}} \tn % Row 0 \SetRowColor{LightBackground} `int {\bf{socket(}}int domain, int type, int protocol{\bf{)}}` & Creates a socket. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `int {\bf{close(}}int sockid{\bf{)}}` & Closes a socket. \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `int {\bf{bind(}}int sockid, struct sockaddr* addr, int addrlen{\bf{)}}` & Selects the port which is going to be used and reserves it for use by the socket.\{\{nl\}\}{\bf{It can be skipped for TCP and UDP sockets}}. \tn % Row Count 12 (+ 7) % Row 3 \SetRowColor{white} `int {\bf{listen(}}int sockid, int backlog{\bf{)}}` & Listens for connections.\{\{nl\}\}{\bf{It's only used by a TCP server}}. \tn % Row Count 16 (+ 4) % Row 4 \SetRowColor{LightBackground} `int {\bf{accept(}}int sockid, struct sockaddr* clientAddr, int* addrlen{\bf{)}}` & Establishes a connection for a {\bf{TCP server}}.\{\{nl\}\}\{\{fa-exclamation\}\}addrlen should be set to \seqsplit{`sizeof(clientAddr)`}. \tn % Row Count 22 (+ 6) % Row 5 \SetRowColor{white} `int {\bf{connect(}}int sockid, struct sockaddr* serverAddr, int addrlen{\bf{)}}` & Establishes a connection for a {\bf{TCP client}}.\{\{nl\}\}\{\{fa-exclamation\}\}addrlen should be set to \seqsplit{`sizeof(clientAddr)`}. \tn % Row Count 28 (+ 6) % Row 6 \SetRowColor{LightBackground} `int {\bf{send(}}int sockid, void* msg, int len, int flags{\bf{)}}` & Sends a message to a {\bf{TCP client/server}} with length `len`. \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Sockets (cont)}} \tn % Row 7 \SetRowColor{LightBackground} `int {\bf{recv(}}int sockid, void* buffer, int len, int flags{\bf{)}}` & Receives a message from a {\bf{TCP client/server}} with length `len`. \tn % Row Count 4 (+ 4) % Row 8 \SetRowColor{white} `int {\bf{sendto(}}int sockid, void* msg, int len, int flags, struct sockaddr* foreign, int addrlen{\bf{)}}` & Sends a message to a {\bf{UDP client/server}} with length `len`. \tn % Row Count 10 (+ 6) % Row 9 \SetRowColor{LightBackground} `int {\bf{recvfrom(}}int sockid, void* msg, int len, int flags, struct sockaddr* foreign, int addrlen{\bf{)}}` & Receives a message from a {\bf{UDPclient/server}} with length `len`. \tn % Row Count 16 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}