\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{Torvak} \pdfinfo{ /Title (c-programmation-de-socket.pdf) /Creator (Cheatography) /Author (Torvak) /Subject (C Programmation de Socket 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}{008729} \definecolor{LightBackground}{HTML}{F7FBF8} \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 Programmation de Socket Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Torvak} via \textcolor{DarkBackground}{\uline{cheatography.com/32041/cs/9815/}}} \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}Torvak \\ \uline{cheatography.com/torvak} \\ \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 25th November, 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Socket Client (TCP)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/torvak_1478947733_SocketRepresentation.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{En mode connecté (TCP) la socket doit être branchée de manière explicite à la partie distante pendant toute la durée des échanges de messages. \newline \textgreater{} Demande de connextion pour le client : connect() \newline \textgreater{} Attente de connnexion pour le serveur : listen() puis accept} \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}{Socket serveur (TCP)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/torvak_1478953701_SocketRepresentationServeur.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Création de socket}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`int socket (int domaine, int type, int protocole);`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `int domaine` & {\emph{ AF\_UNIX ou AF\_INET ou PF\_INET}} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `int type` & {\emph{ SOCK\_DGRAM ou SOCK\_STREAM}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `int protocole` & {\emph{ 0: protocol par défaut (UDP ou TCP)}} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} `INADDR\_ANY` & addresse de la machine \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} `AF\_INET` & {\emph{ Address Family, Internet = IP Addresses}} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} `PF\_INET` & {\emph{ Protocol Family, Internet = IP, TCP/IP or UDP/IP}} \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} `AF\_UNIX = AF\_LOCAL` & {\emph{ communication entre processsus au sein d'une même machine}} \tn % Row Count 16 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{`SOCK\_STREAM`} & {\emph{ pour sockets orientés {\bf{stream}}}} \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Côté client nous devons configurer: la partie {\bf{local}} et la partie qui sera {\bf{connecté au serveur}}} \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}{Attachement socket}} \tn % Row 0 \SetRowColor{LightBackground} `int bind ( \{\{nl\}\} int descripteur, \{\{nl\}\} struct sockaddr* adr, \{\{nl\}\} int longueurAdr\{\{nl\}\});` & {\emph{\{\{nl\}\}descripteur\{\{nl\}\}point -\textgreater{} adr attachement\{\{nl\}\}long. adr en octets}} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`long inet\_addr (const char* adrIP)`} \tn % Row Count 6 (+ 1) \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}{Configuration de socket}} \tn % Row 0 \SetRowColor{LightBackground} `struct in\_addr \{ \{\{nl\}\} u\_long s\_addr;\{\{nl\}\} \};` & Add IP de la machine \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `struct sockaddr\_in \{ \{\{nl\}\} short sin\_family;\{\{nl\}\}u\_short sin\_port;\{\{nl\}\}struct in\_addr sin\_addr;\{\{nl\}\}char sin\_zero{[}8{]};\{\{nl\}\}\};` & Addr d'1 socket\{\{nl\}\}AF\_INT\{\{nl\}\}num port\{\{nl\}\}adr IP\{\{nl\}\}champ de 8 '\textbackslash{}0' \tn % Row Count 10 (+ 7) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{EXEMPLE D'ATTACHEMENT}}\{\{nl\}\}{\bf{{\emph{//Declaration}}}}\{\{nl\}\}`struct sockaddr\_in adrLocale;`\{\{nl\}\} {\bf{{\emph{//Configuration}}}}` \{\{nl\}\} memset((char{\emph{)\&adrLocale,'\textbackslash{}0',sizeof(struct sockaddr\_in)); \{\{nl\}\}adrLocale.sin\_family = AF\_INET; \{\{nl\}\}adrLocale.sin\_addr.s\_addr = htonl(INADDR\_ANY);\{\{nl\}\}adrLocale.sin\_port = htons(numPort);\{\{nl\}\}bind(descripteur, (struct sockaddr}}) \&adrLocale, sizeof(struct sockaddr));`} \tn % Row Count 18 (+ 8) \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}{Fonctions d'utilisation de socket}} \tn % Row 0 \SetRowColor{LightBackground} `int connect ( \{\{nl\}\} descripteurSocket,\{\{nl\}\} \&adrServeur,\{\{nl\}\} longueur\_adr\{\{nl\}\});` & même prototye que bind\{\{nl\}\}int descripteurSocket\{\{nl\}\}struct sockaddr* adrServeur\{\{nl\}\}int longueur\_adr \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} `int listen (\{\{nl\}\}descSocketEcoute,\{\{nl\}\}nbPendantes\{\{nl\}\});` & \{\{nl\}\}int descripteurSocketEcoute\{\{nl\}\}int nbMax de connexions pendantes \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} `int accept(\{\{nl\}\}descSockEcoute, \{\{nl\}\}\&servStore,\{\{nl\}\}longueurAdr\{\{nl\}\});` & \{\{nl\}\}int descripteurSockEcoute\{\{nl\}\}struct sockaddr* servStore\{\{nl\}\}int longueurAdr \tn % Row Count 15 (+ 5) % Row 3 \SetRowColor{white} `int send = ( \{\{nl\}\}descripteurSocket, \{\{nl\}\}message, \{\{nl\}\}strlen(message), \{\{nl\}\}option\{\{nl\}\});` & \{\{nl\}\}int descripterSocket\{\{nl\}\}char message{[}{]}\{\{nl\}\}int longueurMessage\{\{nl\}\}0 \tn % Row Count 20 (+ 5) % Row 4 \SetRowColor{LightBackground} `int recv ( \{\{nl\}\}descripteurSocket, \{\{nl\}\}message, \{\{nl\}\}strlen(message), \{\{nl\}\}option\{\{nl\}\});` & \{\{nl\}\}int descripterSocket\{\{nl\}\}char message{[}{]}\{\{nl\}\}int longueurMaxiMsg\{\{nl\}\}0 \tn % Row Count 25 (+ 5) % Row 5 \SetRowColor{white} `int shutdown(\{\{nl\}\}descripteurSocket, \{\{nl\}\}sens\{\{nl\}\});` & \{\{nl\}\}int descSocket\{\{nl\}\}0: lect; 1:ecrit; 2: les deux \tn % Row Count 28 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`int close(int descriteur);`} \tn % Row Count 29 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.24 cm} x{3.76 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Inclusions bibliothèques nécessaires}} \tn % Row 0 \SetRowColor{LightBackground} `\#include \textless{}sys/socket.h\textgreater{}` & socket() et bind() \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `\#include \textless{}netinet/in.h\textgreater{}` & in\_addr et sockaddr\_in \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `\#include \textless{}arpa/inet.h\textgreater{}` & htonl, htons,inet\_addr \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `\#include \textless{}unistd.h\textgreater{}` & close() \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\#include \textless{}stdio.h\textgreater{}`} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\#include \textless{}stdlib.h\textgreater{}`} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\#include \textless{}string.h\textgreater{}`} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\#include \textless{}sys/types.h\textgreater{}`} \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\#include \textless{}netdb.h\textgreater{}`} \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.12 cm} x{2.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Fonctions de conversion}} \tn % Row 0 \SetRowColor{LightBackground} `uint32\_t htonl(uint32\_t hostlong);` & host to network long \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `uint16\_t htons(uint16\_t hostshort);` & host to network short \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `uint32\_t ntohl(uint32\_t netlong);` & network to host long \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `uint16\_t ntohs(uint16\_t netshort);` & network to host short \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{1.12 cm} x{6.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Specificateur de type lors de printf ou scanf}} \tn % Row 0 \SetRowColor{LightBackground} \%d & int \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \%s & string \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \%c & char \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \%f & float \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \%p & pointer \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \%u & unsigned int \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Squelette Client}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int main()\{ \newline {\bf{//DECLARATION VARIABLES}} \newline int clientSocket, connexion, reception, envoie, deconnexion; \newline struct sockaddr\_in serverAddr; \newline struct sockaddr\_in localAddr; \newline socklen\_t addr\_size; \newline char requete{[}{]} = "test"; \newline char reponse{[}1024{]}; \newline long port = 10500; \newline long ip = \seqsplit{inet\_addr("193.50.225.215");} \newline \newline {\bf{//TRAITEMENT}} \newline \newline {\bf{{\emph{// Création de la socket}}}} \newline printf("Creation de la socket.....\textbackslash{}n"); \newline clientSocket = socket(PF\_INET, SOCK\_STREAM, 0); \newline \newline {\bf{{\emph{// Configuration des parametres de ma struct de l'addresse locale}}}} \newline printf("Configuration de la struct d'addresse locale\textbackslash{}n"); \newline memset(localAddr.sin\_zero, '\textbackslash{}0', \seqsplit{sizeof(localAddr.sin\_zero));} \newline localAddr.sin\_family = AF\_INET; \newline localAddr.sin\_port = htons(0); {\bf{{\emph{//port locale}}}} \newline localAddr.sin\_addr.s\_addr = htonl (INADDR\_ANY); {\bf{{\emph{//Adr. locale}}}} \newline bind(clientSocket, (struct sockaddr{\emph{) \&localAddr, sizeof(struct sockaddr)); {\bf{}}//Association IP et port}}{\emph{ \newline \newline {\bf{}}// Configuration des parametres de la struct de l'addresse du serveur }}{\emph{ \newline printf("Configuration de la struct d'addresse serveur\textbackslash{}n"); \newline memset(serverAddr.sin\_zero, '\textbackslash{}0', \seqsplit{sizeof(serverAddr.sin\_zero));} \newline serverAddr.sin\_family = AF\_INET; \newline serverAddr.sin\_port = htons(port); {\bf{}}//port du serveur}}{\emph{ \newline serverAddr.sin\_addr.s\_addr = inet\_addr("127.0.0.1"); {\bf{}}// Adr. du serveur}}{\emph{ \newline \newline {\bf{}}//Connexion du serveur}}{\emph{ \newline addr\_size = sizeof serverAddr; \newline connect(clientSocket, (struct sockaddr }}) \&serverAddr, \newline \newline {\bf{{\emph{//Boucle de communication avec le serveur}}}} \newline while(!fini) \{ \newline {\bf{{\emph{//Envoie de la requete au serveur}}}} \newline send(clientSocket, requete, strlen(requete), 0); \newline {\bf{{\emph{//Attente de la réponse du serveur}}}} \newline recv(clientSocket, reponse, strlen(reponse), 0); \newline \} \newline {\bf{{\emph{// Deconnexion et fermeture de la socket}}}} \newline shutdown(clientSocket, 2); \newline close(clientSocket); \newline \newline return 0; \newline \}} \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}{Squelette serveur}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int main()\{ \newline \newline {\bf{//DECLARATION }} \newline int socketEcoute, socketService, attachement, connexion, reception, envoie, deconnexion, fermeture; \newline int dialogueClient = 1; \newline char reponse{[}1024{]}; \newline struct sockaddr\_in serverAddr; \newline struct sockaddr\_storage serverStorage; \newline socklen\_t addr\_size; \newline long port = 10500; \newline \newline {\bf{//TRAITEMENT}} \newline {\bf{{\emph{// Creation de la socket ecoute}}}} \newline printf("Creation de socketEcoute.....\textbackslash{}n"); \newline socketEcoute = socket(PF\_INET, SOCK\_STREAM, 0); \newline \newline {\bf{{\emph{// Configuration des parametres de la struct de l'addresse du serveur }}}} \newline memset(serverAddr.sin\_zero, '\textbackslash{}0', sizeof serverAddr.sin\_zero); \newline serverAddr.sin\_family = AF\_INET; \newline serverAddr.sin\_port = htons(port); \newline serverAddr.sin\_addr.s\_addr = htonl(INADDR\_ANY); \newline \newline \newline {\bf{{\emph{//Attachement}}}} \newline printf("Attachement de socketEcoute....\textbackslash{}n"); \newline attachement = bind(socketEcoute, (struct sockaddr {\emph{) \&serverAddr, sizeof(serverAddr)); \newline \newline {\bf{}}//Mise à l'ecoute (maxi 5 connections)}}{\emph{ \newline if(listen(socketEcoute,5)==0) \newline printf("Mise a l'ecoute.....\textbackslash{}n\textbackslash{}n"); \newline else \newline printf("Erreur de mise a l'ecoute\textbackslash{}n\textbackslash{}n"); \newline \newline {\bf{}}//Attente connexion}}{\emph{ \newline while(1) \{ \newline addr\_size = sizeof serverStorage; \newline socketService = accept(socketEcoute, (struct sockaddr }}) \&serverStorage, \&addr\_size); \newline \newline {\bf{{\emph{//Dialogue avec le client}}}} \newline while(1) \{ \newline {\bf{{\emph{//Lecture de la requete du client}}}} \newline \newline {\bf{{\emph{//Envoie de la reponse au client}}}} \newline \} \newline {\bf{{\emph{// Terminaison et fermeture socket de service }}}} \newline shutdown(socketService, 2); \newline \} \newline {\bf{{\emph{//Fermeture de la socket d'écoute}}}} \newline close(socketService); \newline \newline return 0; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Fonctions en C}} \tn % Row 0 \SetRowColor{LightBackground} `memset(char* chaine, char car, int n)` & Retourne la {\bf{chaine}} avec {\bf{char}} au debut {\bf{n}} fois \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `int toupper(str{[}i{]})` & Mettre le car en param. en majuscule \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `int tolower(str{[}i{]})` & Mettre le car en param. en minuscule \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} `int strlen(str)` & retourne longueur de la chaîne \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} `int strcmp(str1, str2)` & Valeurs de retours:\{\{nl\}\} \textless{} 0 si str1 \textless{} str2 \{\{nl\}\} \textgreater{} 0 si str1 \textgreater{} str2 \{\{nl\}\} = 0 si str1== str2 \tn % Row Count 14 (+ 5) % Row 5 \SetRowColor{white} `strcpy(str1,str2)` & Copier contenu de str2 dan str1 \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Exemple de fonction en c:}} \newline `int chercherIndexCar(char car, char jeu{[}{]}, int tailleJeu) \{ \{\{nl\}\} int colonne = -1;\{\{nl\}\}int c = 0;\{\{nl\}\}while(c \textless{} tailleJeu) \{v\{\{nl\}\}if (jeu{[}c{]} == car) \{\{\{nl\}\} colonne = c;\{\{nl\}\} break;\{\{nl\}\}\}\{\{nl\}\}c++;\{\{nl\}\}\} \{\{nl\}\}return colonne; \{\{nl\}\}\}` \newline {\bf{ Exemple d'appel de fonction en c:}} \newline `int index = \seqsplit{chercherIndexCar(chercherIndexCar(car}, jeu, nbLignes*nbColonnes);`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.16 cm} x{3.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Fonctions, Procédures et passage de paramètre}} \tn % Row 0 \SetRowColor{LightBackground} `void proc(char chaine{[}{]}) \{...\}` & chaine est passé par addresse \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `void proc(int num) \{...\}` & num est passé par valeur \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `void proc(int *num) \{...\}` & num est passé par addresse \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`{\bf{Declaration}}\{\{nl\}\}void afficher(int lignes, int colonnes, char chaine{[}{]}{[}colonnes{]})\{...\}\{\{nl\}\}char morpion{[}3{]}{[}3{]};\{\{nl\}\}{\bf{Appel}}\{\{nl\}\}afficher(3, 3, morpion);`} \tn % Row Count 10 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`{\bf{Fonction d'affichage de tableau di-dim:}}\{\{nl\}\}void afficher(int lignes, int colonnes, char chaine{[}{]}{[}colonnes{]}) \{ \{\{nl\}\}int i = 0;\{\{nl\}\}int j = 0;\{\{nl\}\}while (i \textless{} lignes) \{\{\{nl\}\}while (j \textless{} colonnes) \{\{\{nl\}\}printf("\%c", chaine{[}i{]}{[}j{]});\{\{nl\}\}j++;\{\{nl\}\}\}\{\{nl\}\}printf("\textbackslash{}n");\{\{nl\}\}i++;\{\{nl\}\} j = 0;\{\{nl\}\}\}\{\{nl\}\}\}\{\{nl\}\}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}