\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{loikun} \pdfinfo{ /Title (langage-c.pdf) /Creator (Cheatography) /Author (loikun) /Subject (Langage C 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}{EB4E00} \definecolor{LightBackground}{HTML}{FDF3EF} \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{Langage C Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{loikun} via \textcolor{DarkBackground}{\uline{cheatography.com/196466/cs/41286/}}} \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}loikun \\ \uline{cheatography.com/loikun} \\ \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 18th December, 2023.\\ 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{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Sommaire}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{1 Types} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{2 Constantes} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{3 Opérateurs} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{4 Opérateurs sizeof et mémoire} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{5 Conversion de type} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{6 Tests} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{7 Boucles} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{8 Pointeur} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{9 Tableaux} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{10 Fonctions} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{11 Structures} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{12 Chaîne de caractères (Strings)} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{13 Fichiers} \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.2175 cm} x{6.2419 cm} x{6.4106 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{{\bf{entiers}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `char` & 1 octets & -128 ~ à ~ 127 \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} `short` & 2 octets & -32 768 ~ à ~ 32 767 \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} `int` & 4 octets & -2 147 483 648 ~ à ~ 2 147 483 647 \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} `\{\{lang-c\}\}unsigned type` & pour un type entier non signé. \{\{nl\}\} Exemple: `\{\{lang-c\}\} unsigned char` 0 à 255 & \tn % Row Count 15 (+ 6) % Row 5 \SetRowColor{white} \mymulticolumn{3}{x{17.67cm}}{{\bf{virgule flottante}}} \tn % Row Count 16 (+ 1) % Row 6 \SetRowColor{LightBackground} `\{\{lang-c\}\}float` & 2 octets & -3.4e38 ~ à ~ 3.4e38 \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} \{\{bb\}\}`double` & \{\{bb\}\}4 octets & \{\{bb\}\}- 1.7e308 ~ à ~ 1.7e308 \tn % Row Count 22 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{Le `type` n'est utilisé qu'à 2 occasions : \newline - déclaration d'une variable, ~ `\{\{lang-c\}\}int a = 2;` `\{\{lang-c\}\}double var2 = 31.4;` \newline - entête d'une fonction pour préciser les paramètres et le retour, \{\{nl\}\} `int fonction ( double a, char b) \{...\}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break1}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.5626 cm} x{10.7074 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Constantes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{entières}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\{\{lang-c\}\}11` & en base 10 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `\{\{lang-c\}\}0xB` & en base 16 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} `\{\{lang-c\}\}0b1011` & en base 2 \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{réelles}}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{`\{\{lang-c\}\}31.4`} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} `\{\{lang-c\}\}3.14e1` & en notation ingénieur (3.14 x 10\textasciicircum{}1\textasciicircum{}= 31.4) \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{{\bf{caractères}}} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} `\{\{lang-c\}\}'A'` & le code ASCII du caractère A : 65. \{\{nl\}\}`\{\{lang-c\}\} char c ='A';` \{\{fa-arrows-h\}\} `\{\{lang-c\}\} char c = 65;` \tn % Row Count 15 (+ 5) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{{\bf{chaines de caractères}}} \tn % Row Count 16 (+ 1) % Row 10 \SetRowColor{LightBackground} `\{\{lang-c\}\}"Hello world"` & un tableau de caractères constant (lecture seule) \tn % Row Count 19 (+ 3) % Row 11 \SetRowColor{white} `\{\{lang-c\}\}"A"` & un tableau de 2 caractères contenant 'A' et '\textbackslash{}0' le caractère de fin de chaîne. \tn % Row Count 23 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break2}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.687 cm} x{7.2541 cm} x{7.9289 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Opérateurs}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{{\bf{Arithmétiques}} ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ `\{\{lang-c\}\}(a=1, b=2)`} \tn % Row Count 14 (+ 14) % Row 1 \SetRowColor{white} + & addition & `\{\{lang-c\}\}a+2 == 3` \tn % Row Count 16 (+ 2) % Row 2 \SetRowColor{LightBackground} - & soustraction & `\{\{lang-c\}\}b-a ==1` \tn % Row Count 18 (+ 2) % Row 3 \SetRowColor{white} * & multiplication & `\{\{lang-c\}\}a*b == 2` \tn % Row Count 20 (+ 2) % Row 4 \SetRowColor{LightBackground} / & division réelle & `\{\{lang-c\}\}1.0/b == 0.5` \tn % Row Count 22 (+ 2) % Row 5 \SetRowColor{white} / & division entière ou quotient & `\{\{lang-c\}\}1/b == 0` ~ \{\{fa-exclamation-circle\}\} (1/2 == 0) \tn % Row Count 26 (+ 4) % Row 6 \SetRowColor{LightBackground} \% & reste division ou modulo & `\{\{lang-c\}\}3\%b == 1` \tn % Row Count 28 (+ 2) % Row 7 \SetRowColor{white} ++ & incrémentation & `\{\{lang-c\}\}a++ == 2` \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.687 cm} x{7.2541 cm} x{7.9289 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Opérateurs (cont)}} \tn % Row 8 \SetRowColor{LightBackground} || & décrémentation & `\{\{lang-c\}\}a-{}- == 0` \tn % Row Count 2 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{3}{x{17.67cm}}{\{\{bt\}\}{\bf{Relationnel}}} \tn % Row Count 3 (+ 1) % Row 10 \SetRowColor{LightBackground} == & égalité & `\{\{lang-c\}\}a == b` ~ faux(0) \tn % Row Count 5 (+ 2) % Row 11 \SetRowColor{white} != & différent & `\{\{lang-c\}\}a != b` ~ vrai(1) \tn % Row Count 7 (+ 2) % Row 12 \SetRowColor{LightBackground} \textgreater{} & supérieur & `\{\{lang-c\}\}a \textgreater{} b`~ faux(0) \tn % Row Count 9 (+ 2) % Row 13 \SetRowColor{white} \textless{} & inférieur & `\{\{lang-c\}\}a \textless{} b` ~vrai(1) \tn % Row Count 11 (+ 2) % Row 14 \SetRowColor{LightBackground} \textgreater{}= & supérieur ou égal & `\{\{lang-c\}\}a \textgreater{}= b`~ faux(0) \tn % Row Count 13 (+ 2) % Row 15 \SetRowColor{white} \textless{}= & inférieur ou égal & `\{\{lang-c\}\}a \textless{}= b`~ faux(0) \tn % Row Count 15 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{\{\{bt\}\}{\bf{Logique}}} \tn % Row Count 16 (+ 1) % Row 17 \SetRowColor{white} \&\& & ET & `\{\{lang-c\}\}(a==1) \&\& (b==3)` ~ faux(0) \tn % Row Count 19 (+ 3) % Row 18 \SetRowColor{LightBackground} || & OU & `\{\{lang-c\}\}(a==1) || (b==3)` ~ vrai(1) \tn % Row Count 22 (+ 3) % Row 19 \SetRowColor{white} ! & négation & `\{\{lang-c\}\}!(a==b)` ~vrai(1) \tn % Row Count 24 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{\{\{bt\}\}{\bf{Assignation}}} \tn % Row Count 25 (+ 1) % Row 21 \SetRowColor{white} = & assigne à gauche la valeur de droite & `\{\{lang-c\}\} a = 1` \tn % Row Count 28 (+ 3) % Row 22 \SetRowColor{LightBackground} {\emph{op}}= & mettre à jour une variable avec l'opération arithmétique {\emph{op}} & `\{\{lang-c\}\}a+=2; ` \{\{fa-arrows-h\}\} `\{\{lang-c\}\}a=a+2;` \{\{nl\}\}`\{\{lang-c\}\}a\%=1;` \{\{fa-arrows-h\}\} `\{\{lang-c\}\}a=a\%1;` \tn % Row Count 35 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.374 cm} x{6.5793 cm} x{6.9167 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Opérateurs sizeof et mémoire}} \tn % Row 0 \SetRowColor{LightBackground} `\{\{lang-c\}\}sizeof()` & \{\{width=33\}\} taille du type (en octets) & `\{\{lang-c\}\}sizeof(int)` vaut 4. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `\{\{lang-c\}\}\&` & adresse & `\{\{lang-c\}\}\&a` est l'adresse mémoire où `\{\{lang-c\}\}a` est stocké. \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} `\{\{lang-c\}\}*` & variable pointée, \{\{nl\}\} indirection & `\{\{lang-c\}\}*p` est la variable à l'adresse mémoire contenue dans `\{\{lang-c\}\}p`. \{\{nl\}\} Si`\{\{lang-c\}\} p=\&a`, alors `\{\{lang-c\}\}*p` est un autre nom pour la variable `\{\{lang-c\}\}a`. \tn % Row Count 20 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break2 (copy)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.6991 cm} x{11.5709 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Conversion de type}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Implicite lors d'une affectation}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{`\{\{lang-c\}\}int a = 3.9;` \{\{fa-caret-right\}\} `\{\{lang-c\}\}a = 3` (troncature) \{\{nl\}\} `\{\{lang-c\}\}double f = 2/3;` \{\{fa-caret-right\}\} `\{\{lang-c\}\}double f = 0;` \{\{fa-caret-right\}\} `\{\{lang-c\}\}f = 0.0`} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ Implicite entre 2 opérandes de type différent}}} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{`\{\{lang-c\}\}double f = 2.0/3;` \{\{fa-caret-right\}\} `\{\{lang-c\}\}double f = 2.0/3.0;` \{\{fa-caret-right\}\} `\{\{lang-c\}\} f = 0.666` \{\{nl\}\} Règle: opérande de type de plus petite capacité (entier 3) promu vers le type de l'opérande de plus grande capacité (double)} \tn % Row Count 13 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\{\{bt\}\}{\bf{Explicite}}} \tn % Row Count 14 (+ 1) % Row 5 \SetRowColor{white} `\{\{lang-c\}\}( type )` & operateur de conversion de `type`, de cast. \{\{nl\}\} `\{\{lang-c\}\}(double)1/2` \{\{fa-caret-right\}\} `\{\{lang-c\}\}1.0/2` \{\{fa-caret-right\}\} `\{\{lang-c\}\}0.5` \{\{nl\}\} `\{\{lang-c\}\}printf("\%d\textbackslash{}n", (int) 3.94);` ~ affiche `\{\{lang-c\}\}3` \tn % Row Count 23 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break3}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Tests (structure de contrôle)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{if}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}if( condition ) \{` {\emph{//la condition est évaluée.}} \{\{nl\}\} ~ ~ ~ ~ {\emph{//si vrai, ce bloc de 2 instructions est exécuté}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction1;` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction2;`\{\{nl\}\}`\{\{lang-c\}\}\} ` \{\{nl\}\} {\emph{//si faux, le bloc n'est pas exécuté et l'exécution passe ici.}}} \tn % Row Count 9 (+ 8) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{if .. else}}} \tn % Row Count 10 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}if( condition ) \{` {\emph{//la condition est évaluée.}} \{\{nl\}\} ~ ~ ~ ~ {\emph{//si vrai, ce bloc de 2 instructions est exécuté}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction1;` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-cpp\}\}instruction2;` \{\{nl\}\}`\{\{lang-c\}\}\}` \{\{nl\}\}`\{\{lang-c\}\}else \{` \{\{nl\}\} ~ ~ ~ ~{\emph{//si faux, ce bloc est exécuté au lieu du précédent.}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction3;` \{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\}\{\{nl\}\} Exemple: \{\{nl\}\}`\{\{lang-c\}\}if ((n\%2) == 1) \{`\{\{nl\}\} ~ ~ `\{\{lang-c\}\}printf("nombre impair\textbackslash{}n");`\{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\} `\{\{lang-c\}\}else \{`\{\{nl\}\} ~ ~`printf("nombre pair\textbackslash{}n");`\{\{nl\}\} `\{\{lang-c\}\}\}`} \tn % Row Count 25 (+ 15) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{if .. else if .. else if .. else}}} \tn % Row Count 26 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}if( condition1 ) \{` {\emph{//la condition 1 est évaluée.}} \{\{nl\}\}~ ~ ~ ~ {\emph{//si vrai, ce bloc de 2 instructions est exécuté}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction1;` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction2;`\{\{nl\}\}`\{\{lang-cpp\}\}\}` \{\{nl\}\}`\{\{lang-cpp\}\}else if( condition2 )\{` \{\{nl\}\} ~ ~ ~ ~{\emph{//si condition 1 faux mais condition 2 vrai, instruction 3 est exécutée.}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction3;` \{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\}`\{\{lang-c\}\}else \{` \{\{nl\}\} ~ ~ ~ ~ {\emph{//si condition 1 et 2 faux, instruction4 est exécutée.}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-cpp\}\}instruction4;` \{\{nl\}\} `\{\{lang-c\}\}\}`} \tn % Row Count 41 (+ 15) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`( condition )` est un test sur une variable `\{\{lang-c\}\}(a)`, une opération `\{\{lang-c\}\}(a!=1)` ou le résultat d'une fonction `\{\{lang-c\}\}(ftest(param))`. \newline `\{\{lang-c\}\} condition` est FAUX si la valeur est 0, VRAI pour toute valeur différente de 0.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break4}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Boucles (Structure de contrôle)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{while}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}while( condition ) \{ ` \{\{nl\}\} ~ ~ ~ ~{\emph{//exécuter instructions 1 et 2 de ce bloc, tant que condition vrai.}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction1; `\{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction2; ` \{\{nl\}\} ~ ~ ~ ~ {\emph{//retour au test de condition}} \{\{nl\}\} `\{\{lang-c\}\}\} ` \{\{nl\}\} \{\{nl\}\} Exemple : Afficher la suite 0 1 ... 8 9 \{\{nl\}\}`\{\{lang-c\}\}i=0;` \{\{nl\}\}`\{\{lang-c\}\}while(i\textless{}10) \{ ` \{\{nl\}\} `\{\{lang-c\}\} printf("\%d\textbackslash{}n",i);` \{\{nl\}\} `\{\{lang-c\}\} i++; `\{\{nl\}\} `\{\{lang-c\}\}\} `} \tn % Row Count 13 (+ 12) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{do \{ \} while;}}} \tn % Row Count 14 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}do \{ ` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction1; `\{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction2;`\{\{nl\}\} ~ ~ ~ ~ //{\emph{exécuter instructions 1 et 2 du bloc, }} \{\{nl\}\} `\{\{lang-c\}\}\} while( condition ); ` {\emph{//tant que condition vrai.}} \{\{nl\}\} \{\{nl\}\} Contrairement à `\{\{lang-c\}\}while`, le bloc est toujours exécuté au moins une fois même si `\{\{lang-c\}\}condition` est faux dés le départ. \{\{nl\}\} \{\{fa-exclamation-circle\}\} `\{\{lang-c\}\}do .. while();` est la seule boucle avec un `\{\{lang-c\}\};` final.} \tn % Row Count 26 (+ 12) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{for}}} \tn % Row Count 27 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\emph{//Executer initial, puis tester la condition}} \{\{nl\}\} `\{\{lang-c\}\}for ( initial; condition ; iteration) \{ ` \{\{nl\}\} ~ ~ ~ ~ {\emph{//exécuter instructions 1 et 2 de ce bloc, tant que condition vrai.}} \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction1; `\{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instruction2; ` \{\{nl\}\} ~ ~ ~ ~{\emph{//exécuter iteration avant retour au test de condition}} \{\{nl\}\} `\{\{lang-c\}\}\} ` \{\{nl\}\} \{\{nl\}\} Exemple: Afficher la suite 0 1 ... 8 9 \{\{nl\}\}`\{\{lang-c\}\}for (i=0; i\textless{}10; i++) \{ ` \{\{nl\}\} `\{\{lang-c\}\} printf("\%d\textbackslash{}n",i);` \{\{nl\}\} `\{\{lang-c\}\}\} `} \tn % Row Count 40 (+ 13) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Boucles (Structure de contrôle) (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{for \{\{fa-exchange\}\} while équivalence}}} \tn % Row Count 1 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}for ( initial; condition ; iteration) \{ ` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}instructions; ` \{\{nl\}\} `\{\{lang-c\}\}\} ` \{\{nl\}\} \{\{fa-exchange\}\} \{\{nl\}\}`\{\{lang-c\}\}initial; ` \{\{nl\}\} `\{\{lang-c\}\}while( condition ) \{ ` \{\{nl\}\} ~ ~ ~ ~ `\{\{lang-c\}\}instructions; ` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}iteration;`\{\{nl\}\} `\{\{lang-c\}\}\} `} \tn % Row Count 9 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}break;` ~ sortir immédiatement d'une boucle : la boucle la plus proche si dans des boucles imbriquées. \newline `\{\{lang-c\}\}continue;` ~ ignorer les instructions de la boucle situées après `\{\{lang-c\}\}continue;`, et retourner au test de la condition. Si dans une boucle `\{\{lang-c\}\}for`, exécuter l'instruction d'iteration avant le test.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break5}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Pointeur}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Un pointeur est une adresse mémoire (pointeur == adresse). Un type adresse est `type*`. \{\{nl\}\}Ex: `double*` est le type \{adresse d'un double\}. \{\{nl\}\}{\bf{Declaration}}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `\{\{lang-c\}\}type *p;` & `\{\{lang-c\}\}p` est l'adresse d'une variable de type `type`. \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} `\{\{lang-c\}\}int *p = NULL;` & `\{\{lang-c\}\}p` est l'adresse d'un entier. \{\{nl\}\} Initialisé à l'adresse invalide `\{\{lang-c\}\}NULL` (`\{\{lang-c\}\}0`, une bonne pratique). \tn % Row Count 14 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{RAM d'un CPU 64bits (adresses codées sur 8 octets) après l'initialisation avec NULL : \{\{nl\}\}Variables: `\{\{lang-c\}\} p `\{\{nl\}\} `-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}--`\{\{nl\}\} `\{\{lang-c\}\} | 0x0000 (8 octs) | `\{\{nl\}\} `-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}--` \{\{nl\}\} @mem:`\{\{lang-c\}\} 0x040 0x048 `} \tn % Row Count 22 (+ 8) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Initialisation (2 options)}}} \tn % Row Count 23 (+ 1) % Row 5 \SetRowColor{white} `\{\{lang-c\}\}int *p = malloc( sizeof(int) );` \{\{nl\}\} \{\{fa-arrows-h\}\} `\{\{lang-c\}\}int *p;` \{\{nl\}\} `\{\{lang-c\}\}p=malloc( sizeof(int) );` & Initialise `\{\{lang-c\}\}p` avec l'adresse d'un bloc de 4 octets réservé avec `\{\{lang-c\}\}malloc()`. \tn % Row Count 30 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Pointeur (cont)}} \tn % Row 6 \SetRowColor{LightBackground} `\{\{lang-c\}\}int *p = \&a;` \{\{nl\}\} \{\{fa-arrows-h\}\} `\{\{lang-c\}\} int *p; p=\&a;` & Initialise `\{\{lang-c\}\}p` avec l'adresse de `\{\{lang-c\}\}a` (avec `\{\{lang-c\}\}int a=11;`;) \tn % Row Count 5 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{Variables: `\{\{lang-c\}\} p a`\{\{nl\}\} `-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}--`\{\{nl\}\} `\{\{lang-c\}\} | 0xC10 | | 11 |`\{\{nl\}\} `-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}--` \{\{nl\}\} @mem:`\{\{lang-c\}\} 0x040 0x048 0xC10 0xC14`} \tn % Row Count 12 (+ 7) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Usage}}} \tn % Row Count 13 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{\{\{fa-exclamation-triangle\}\} Un pointeur ne peut pas être utilisé avant son initilialisation avec une adresse valide.} \tn % Row Count 16 (+ 3) % Row 10 \SetRowColor{LightBackground} `\{\{lang-c\}\}p` & une adresse \{\{nl\}\} Ex: `\{\{lang-c\}\}p=\&a` \{\{fa-arrows-h\}\} `\{\{lang-c\}\}p=0xC10` \tn % Row Count 20 (+ 4) % Row 11 \SetRowColor{white} `\{\{lang-c\}\}*p` & la variable pointée : `\{\{lang-c\}\}a`. \{\{nl\}\} Ex: `\{\{lang-c\}\}*p= 12 ` \{\{fa-arrows-h\}\} `\{\{lang-c\}\}a=12;` \tn % Row Count 26 (+ 6) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Variables: `\{\{lang-c\}\} p -{}-{}-{}-{}-{}-{}- * -{}-{}-{}-{}-{}-{}-\textgreater{} a`\{\{nl\}\} `-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}--`\{\{nl\}\} `\{\{lang-c\}\} | 0xC10 | | 12 |`\{\{nl\}\} `-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}--` \{\{nl\}\} @mem:`\{\{lang-c\}\} 0x040 0x048 0xC10 0xC14`} \tn % Row Count 33 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Pointeur (cont)}} \tn % Row 13 \SetRowColor{LightBackground} `\{\{lang-c\}\}p+i` ~ ~ (avec i entier) & adresse du i\textasciicircum{}ème\textasciicircum{} `\{\{lang-c\}\}int` en mémoire après `\{\{lang-c\}\}p`. \{\{nl\}\} Donc `\{\{lang-c\}\}p+i` vaut `\{\{lang-c\}\}p+i*sizeof(int)`, quand `\{\{lang-c\}\}p` est de type `\{\{lang-c\}\}int*`. \tn % Row Count 10 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break6}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Tableaux}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Tableau statique}} \{\{nl\}\}La taille du tableau est déterminée à la compilation et elle est fixe pendant toute l'exécution. La taille est une {\emph{constante}}.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `\{\{lang-c\}\}int t{[}3{]};` & un tableau de 3 entiers (valeurs aléatoires) \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} `\{\{lang-c\}\}double tab{[}4{]}=\{-1.2, 3.2\};` & un tableau de 4 `\{\{lang-c\}\}double`. \{\{nl\}\} Les 2 premiers éléments sont -1.2 et 3.2, les 2 autres nuls. \tn % Row Count 13 (+ 6) % Row 3 \SetRowColor{white} `\{\{lang-c\}\}double tab{[}{]}=\{-1.2, 3.2\};` & un tableau de `\{\{lang-c\}\}double`, taille 2 imposé par l'initialisation \tn % Row Count 17 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Tableau dynamique }} \{\{nl\}\}La taille du tableau est déterminée pendant l'exécution et peut être modifiée. La taille est généralement une {\emph{variable}}.} \tn % Row Count 21 (+ 4) % Row 5 \SetRowColor{white} `\{\{lang-c\}\}double *tab;` \{\{nl\}\} `\{\{lang-c\}\}tab = (double*) malloc ( n*sizeof (int) );` & un tableau de `\{\{lang-c\}\}n` `\{\{lang-c\}\}double.` \{\{nl\}\} Valeurs initiales aléatoires. \tn % Row Count 26 (+ 5) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ Equivalence pointeur et nom d'un tableau }}} \tn % Row Count 27 (+ 1) % Row 7 \SetRowColor{white} `\{\{lang-c\}\} tab ` \{\{fa-arrows-h\}\} `\{\{lang-c\}\}\&tab{[}0{]}` \{\{nl\}\} `\{\{lang-c\}\}tab+i` \{\{fa-arrows-h\}\} `\{\{lang-c\}\}\&tab{[}i{]}` & L'identifiant d'un tableau est l'adresse de son premier élément. \{\{nl\}\} Par nature pour un tableau dynamique, où `\{\{lang-c\}\}tab` est un pointeur. \{\{nl\}\}Par définition pour un tableau statique, où l'identifiant est un alias pour l'adresse du 1\textasciicircum{}er\textasciicircum{} élément. \tn % Row Count 41 (+ 14) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Tableaux (cont)}} \tn % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{accès aux éléments d'un tableau statique ou dynamique}}} \tn % Row Count 2 (+ 2) % Row 9 \SetRowColor{white} `\{\{lang-c\}\}tab{[}i{]}` \{\{nl\}\} ou \{\{nl\}\} `\{\{lang-c\}\}*(tab+i)` & i+1\textasciicircum{}ième\textasciicircum{} élément avec i=0,...taille-1 \{\{nl\}\} `\{\{lang-c\}\}tab{[}0{]}` est le premier élément. \{\{nl\}\} `\{\{lang-c\}\}tab+i` est l'adresse du i\textasciicircum{}ème\textasciicircum{} élément après le premier. \tn % Row Count 11 (+ 9) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ Copie entre deux tableaux }}} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{`\{\{lang-c\}\}for (i=0; i\textless{} taille ; i++) \{` \{\{nl\}\} ~ ~ `\{\{lang-c\}\} tab1{[}i{]}=tab2{[}i{]};` \{\{nl\}\} `\{\{lang-c\}\}\}`\{\{nl\}\}\{\{nl\}\} \textasciitilde{}\textasciitilde{}`\{\{lang-c\}\}tab1 = tab2;`\textasciitilde{}\textasciitilde{} ne copie pas les éléments, c'est une copie entre 2 adresses. \{\{nl\}\} L'opération est incorrecte si `\{\{lang-c\}\}tab1` est un tableau dynamique (un pointeur). Aucune copie d'éléments n'est effectué : le même tableau `\{\{lang-c\}\}tab2` est accessible via `\{\{lang-c\}\}tab1` et `\{\{lang-c\}\}tab2`. \{\{nl\}\} L'opération est illégale si `\{\{lang-c\}\}tab1` est un tableau statique : `\{\{lang-c\}\}tab1` est une adresse constante non modifiable.} \tn % Row Count 24 (+ 12) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ Comparaison du contenu de deux tableaux}}} \tn % Row Count 25 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{`\{\{lang-c\}\}equal=1; ` \{\{nl\}\} `\{\{lang-c\}\}for (i=0; i\textless{} taille ; i++) \{` \{\{nl\}\} ~ ~ `\{\{lang-c\}\}if( tab1{[}i{]}!=tab2{[}i{]} ) \{` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}equal=0;` \{\{nl\}\} ~ ~ ~ ~`\{\{lang-c\}\}break;` \{\{nl\}\} ~ ~ `\{\{lang-c\}\}\}` \{\{nl\}\} `\{\{lang-c\}\}\}`\{\{nl\}\}\{\{nl\}\} \textasciitilde{}\textasciitilde{}`\{\{lang-c\}\}tab1 == tab2`\textasciitilde{}\textasciitilde{} ne compare pas le contenu, mais l'adresse mémoire des premiers éléments de `\{\{lang-c\}\}tab1` et `\{\{lang-c\}\}tab2` : donc test toujours FAUX.} \tn % Row Count 35 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break7}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Fonctions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Passage par valeur}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Pour passer des valeurs à une fonction}}: la fonction utilise le type de retour (`\{\{lang-c\}\}return`) pour son résultat. \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}double add5( double value )` ~ ~ ~ ~ ~ ~ {\emph{//la variable locale value est initialisée avec 3.14, la valeur de n}} \{\{nl\}\} `\{\{lang-c\}\}\{ double res= value+5;` \{\{nl\}\} ~ ~ `\{\{lang-c\}\}return res; ` \{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\} \{\{nl\}\} `int main()` \{\{nl\}\} `\{\{lang-c\}\}\{ double n=3.14;` \{\{nl\}\} ~ ~ `\{\{lang-c\}\}n= add5(n);` ~ ~ ~ ~ ~ ~~ ~~ ~ ~ ~ ~ ~ ~ ~ {\emph{//on passe la valeur n.}} \{\{nl\}\} `\{\{lang-c\}\} ...` ~ ~ ~ ~ ~ ~ ~ ~~ ~ ~ ~~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ {\emph{//n vaut maintenant 8.14}} \{\{nl\}\} `\{\{lang-c\}\}\}`} \tn % Row Count 19 (+ 18) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Passage par adresse}}} \tn % Row Count 20 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Pour passer des variables à une fonction}}: la fonction retourne ses résultats en modifiant les variables d'origines via leurs adresses. \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}void add5( double *var )` ~ ~ ~ ~ ~ ~ {\emph{//le pointeur var est initialisé avec adresse de n}} \{\{nl\}\} `\{\{lang-c\}\}\{ *var = *var + 5;` ~ ~ ~ ~ ~ ~ ~ ~ ~ ~{\emph{//operateur d'indirection pour accéder à la variable pointée n}} \{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}\{ ...` \{\{nl\}\} `\{\{lang-c\}\}double n=3.14;` \{\{nl\}\} `\{\{lang-c\}\}add5(\&n);` ~ ~ ~ ~ ~ ~ ~ ~~ ~~ ~ ~ ~ ~ ~ ~ ~ {\emph{//on passe l'adresse de n.}} \{\{nl\}\} `\{\{lang-c\}\}... \}` ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~~ ~ ~ ~~ ~ ~ ~ ~ ~ {\emph{//n vaut maintenant 8.14.}} \{\{nl\}\} \{\{nl\}\} Note: l'adresse mémoire est le moyen pour la fonction `\{\{lang-c\}\}add5()`d'accéder à des variables qui ne lui appartiennent pas, et donc lui sont inconnues (cf portée des variables).} \tn % Row Count 43 (+ 23) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Fonctions (cont)}} \tn % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Passage par adresse pour retourner plusieurs résultats}}} \tn % Row Count 2 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Car `\{\{lang-c\}\}return` ne permet de retourner qu'un résultat \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}void divisionEntiere ( int nombre, int diviseur, int *quotient, int *reste )`\{\{nl\}\} `\{\{lang-c\}\}\{`~ ~ `\{\{lang-c\}\} *quotient = nombre/diviseur;`\{\{nl\}\} ~ ~ ~ `\{\{lang-c\}\} *reste = nombre\%diviseur;` \{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}\{ ...` \{\{nl\}\}`\{\{lang-c\}\}int n=7, d=3;` \{\{nl\}\}`\{\{lang-c\}\}int quotient, reminder;` ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~{\emph{//variable pour les résultats}} \{\{nl\}\} `\{\{lang-c\}\}divisionEntiere(n, d, \"ient, \&reminder);` ~ ~ {\emph{//passage de leurs adresses}} \{\{nl\}\} `\{\{lang-c\}\}... \}`} \tn % Row Count 17 (+ 15) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Passage d'un tableau}}} \tn % Row Count 18 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Passer l'adresse du premier élément (\{\{fa-arrows-h\}\} le nom du tableau) et le nombre d'éléments. \{\{nl\}\} Passage par adresse, toute modification des éléments a lieu sur les éléments du tableau d'origine.} \tn % Row Count 23 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\{\{lang-c\}\}void tab\_init( double *tab, int n )` \{\{nl\}\} `\{\{lang-c\}\}\{` ~ `\{\{lang-c\}\}int i=0;` \{\{nl\}\} ~ ~ `\{\{lang-c\}\}for (i=0; i\textless{}n ; i++) \{ tab{[}i{]}=0;` \{\{nl\}\} ~ ~ `\{\{lang-c\}\}\}` \{\{nl\}\}`\{\{lang-c\}\}\}` \{\{nl\}\} `\{\{lang-c\}\}int main()` \{\{nl\}\} `\{\{lang-c\}\}\{ double u{[}3{]};` \{\{nl\}\} ~ `\{\{lang-c\}\}tab\_init(u,3);` \{\{nl\}\} ~ `\{\{lang-c\}\}return(0);` \{\{nl\}\} `\{\{lang-c\}\}\}`} \tn % Row Count 31 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break8}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Structures}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Définition et déclaration d'une structure}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\{\{lang-c\}\}struct person \{ char name{[}30{]};`\{\{nl\}\} ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ `\{\{lang-c\}\}int age;`\{\{nl\}\} ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ `\{\{lang-c\}\}\};` \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}struct person joe, diane;` & Définit le type `\{\{lang-c\}\}struct person` : une structure avec 2 membres ou champs. \{\{nl\}\} Attention: la définition finit avec un `;`. \{\{nl\}\} \{\{nl\}\} \{\{nl\}\}Déclare 2 structures de type `\{\{lang-c\}\}struct person`. \tn % Row Count 17 (+ 16) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Définition et déclaration avec un `\{\{lang-c\}\}typedef`}}} \tn % Row Count 19 (+ 2) % Row 3 \SetRowColor{white} `\{\{lang-c\}\}typedef struct \{ char name{[}30{]};`\{\{nl\}\} ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ `\{\{lang-c\}\}int age;`\{\{nl\}\} ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ `\{\{lang-c\}\}\} person\_t;` \{\{nl\}\} \{\{nl\}\}`\{\{lang-c\}\}person\_t joe, diane;` & Définit le type `\{\{lang-c\}\}person\_t`: une structure avec 2 membres. \{\{nl\}\} `\{\{lang-c\}\}typdef` permet de définir un alias pour un type : utilisé ici pour alléger le type en 2 mots `\{\{lang-c\}\}struct person` en un type en un mot `\{\{lang-c\}\}person\_t`. \{\{nl\}\} \{\{nl\}\}Déclare 2 structures de type `\{\{lang-c\}\}person\_t`. \tn % Row Count 35 (+ 16) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Structures (cont)}} \tn % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ Initialisation à la déclaration }}} \tn % Row Count 1 (+ 1) % Row 5 \SetRowColor{white} `\{\{lang-c\}\}struct person joe =\{"Dupont", 13\};` \{\{nl\}\} `\{\{lang-c\}\}struct person joe =\{.age= 13, .name="Dupont"\};` & Valide à la déclaration. \{\{nl\}\}Après la déclaration, il faut accéder chaque membre séparément pour l'initialiser (cf ci-dessous). \tn % Row Count 8 (+ 7) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Accès aux membres}}} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} `\{\{lang-c\}\}person\_t *pdiane;`\{\{nl\}\}`pdiane= malloc ( sizeof ( person\_t) )`; & Crée 1 structure, allouée via un `\{\{lang-c\}\}malloc()`. \tn % Row Count 13 (+ 4) % Row 8 \SetRowColor{LightBackground} `\{\{lang-c\}\}joe.age= 27;` \{\{nl\}\} `\{\{lang-c\}\}strcpy(diane.name,"Verovski");` \{\{nl\}\} \{\{nl\}\} & operateur `.`, pour accéder à partir d'une structure précède. \{\{nl\}\} \{\{nl\}\} Note: Avec un pointeur `\{\{lang-c\}\}pdiane`, `( *pdiane ).age = 45;` est valide mais écriture déconseillée. \tn % Row Count 23 (+ 10) % Row 9 \SetRowColor{white} `\{\{lang-c\}\}pdiane-\textgreater{}age = 27;` \{\{nl\}\} `\{\{lang-c\}\}strcpy(pdiane-\textgreater{}name,"Verovski");` \{\{nl\}\} \{\{nl\}\} & opérateur `\{\{lang-c\}\}-\textgreater{}`, pour accéder à partir d'un pointeur. \{\{nl\}\} \{\{nl\}\} Note: `\{\{lang-c\}\}(\&joe)-\textgreater{}age=27;` est valide mais écriture déconseillée. \tn % Row Count 31 (+ 8) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Structures (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ copie de structures }}} \tn % Row Count 1 (+ 1) % Row 11 \SetRowColor{white} `\{\{lang-fr\}\}joe = diane;` & Les valeurs des membres de `\{\{lang-c\}\}diane` sont copiés dans les membres de `\{\{lang-c\}\}joe`. \{\{nl\}\} Note : valide entre structures de même type, donc de même taille mémoire, mais invalide pour la copie de tableaux (Voir section tableaux). \tn % Row Count 14 (+ 13) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{ Fonction et strucutre }}} \tn % Row Count 15 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{`\{\{lang-c\}\}void initPerson ( struct person *p )` \{\{nl\}\} `\{\{lang-c\}\}\{ p-\textgreater{}page = 0;` \{\{nl\}\} ~ ~`\{\{lang-c\}\}strcpy(p-\textgreater{}name, "");`\{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}\{...` \{\{nl\}\} `\{\{lang-c\}\} struct person john;` \{\{nl\}\} ~ `\{\{lang-c\}\}initPerson(\&joe);` \{\{nl\}\} `...`} \tn % Row Count 21 (+ 6) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{ou avec typedef : \{\{nl\}\} `\{\{lang-c\}\}void initPerson ( person\_t *p )` \{\{nl\}\} `\{\{lang-c\}\}\{ p-\textgreater{}page = 0;` \{\{nl\}\} ~ ~`\{\{lang-c\}\}strcpy(p-\textgreater{}name, "");`\{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\} \{\{nl\}\} `\{\{lang-c\}\}\{...` \{\{nl\}\} `\{\{lang-c\}\} person\_t john;` \{\{nl\}\} ~ `\{\{lang-c\}\}initPerson(\&joe);` \{\{nl\}\} `...` \{\{nl\}\} \{\{nl\}\} Le passage par adresse est privilégié pour l'efficacité : pas de copie de toutes les valeurs de la structure.} \tn % Row Count 30 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break9}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Chaînes de caractères (Strings)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Déclaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\{\{lang-c\}\}char name{[}30{]};` & un tableau de `\{\{lang-c\}\}char`, pouvant servir à stocker une chaîne. \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} `\{\{lang-c\}\}char name{[}30{]}= " marion " ;` \{\{nl\}\} \{\{fa-arrows-h\}\} `\{\{lang-c\}\}char name{[}30{]}=\{'m','a','r','i','o','n','\textbackslash{}0'\};` & un tableau, initialisé avec la chaîne de caractères `\{\{lang-c\}\}"marion"`. \tn % Row Count 11 (+ 6) % Row 3 \SetRowColor{white} `\{\{lang-c\}\}char name{[}{]}=" marion ";` \{\{nl\}\} \{\{nl\}\} \{\{nl\}\} \textasciitilde{}\textasciitilde{}`\{\{lang-c\}\}char *name=" marion ";`\textasciitilde{}\textasciitilde{} & un tableau de 7 `\{\{lang-c\}\}char` (6+caractère de fin `\{\{lang-c\}\}\textbackslash{}0`, initialisé avec la chaîne de caractères `\{\{lang-c\}\}"marion"`. \{\{nl\}\} \{\{nl\}\} une adresse/pointeur `\{\{lang-c\}\}name` initialisé avec l'adresse d'une chaîne {\emph{constante}} `\{\{lang-c\}\}"marion"`. \{\{nl\}\} A éviter, la chaîne n'est pas modifiable. \tn % Row Count 27 (+ 16) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Initialisation après déclaration}}} \tn % Row Count 28 (+ 1) % Row 5 \SetRowColor{white} `\{\{lang-c\}\}char name{[}30{]};`\{\{nl\}\}\textasciitilde{}\textasciitilde{}`\{\{lang-c\}\}name="marion";`\textasciitilde{}\textasciitilde{} & (Voir Tableaux pour plus de détail). Copie d'adresses et non de contenu : `\{\{lang-c\}\}name` est l'adresse du premier élément de name. \tn % Row Count 35 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Chaînes de caractères (Strings) (cont)}} \tn % Row 6 \SetRowColor{LightBackground} `\{\{lang-c\}\}strcpy(name, " marion ");` & copie la chaîne `\{\{lang-c\}\}" marion "` dans `\{\{lang-c\}\}name`. \tn % Row Count 4 (+ 4) % Row 7 \SetRowColor{white} `\{\{lang-c\}\}sprintf(name, "\%s"," marion ");` & copie la chaîne `\{\{lang-c\}\}"marion"` dans \{\{lang-c\}\}name`. \tn % Row Count 7 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Lire/extraire une chaîne de caractères}}} \tn % Row Count 8 (+ 1) % Row 9 \SetRowColor{white} `\{\{lang-c\}\}scanf("\%s", name);` & Lire {\emph{un mot}} au clavier. Paramètre: adresse du tableau = son identifiant. \tn % Row Count 12 (+ 4) % Row 10 \SetRowColor{LightBackground} `\{\{lang-c\}\}fgets(name, SIZE, stdin);` & Lire une ligne au clavier. Le `\{\{lang-c\}\}'\textbackslash{}n'` est ajouté à la fin de name. SIZE est la taille max du tableau name \tn % Row Count 18 (+ 6) % Row 11 \SetRowColor{white} `\{\{lang-c\}\}sscanf(str, "\%s \%d", name, \&age);` & Comme `\{\{lang-c\}\}printf()` mais la lecture est faite dans la chaîne `\{\{lang-c\}\}printf()` et non la mémoire du clavier \tn % Row Count 24 (+ 6) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Ecrire une chaîne de caractères}}} \tn % Row Count 25 (+ 1) % Row 13 \SetRowColor{white} `\{\{lang-c\}\}strcpy(dest, src);` & Copie la chaîne `\{\{lang-c\}\}src` dans `\{\{lang-c\}\}dest`. Au programmeur de s'assurer que le tableau `\{\{lang-c\}\}dest` est assez grand \tn % Row Count 32 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Chaînes de caractères (Strings) (cont)}} \tn % Row 14 \SetRowColor{LightBackground} `\{\{lang-c\}\}printf("\%s", name);` & Affiche une chaîne de caractère à partir de l'adresse du premier élément du tableau, d'où l'identifiant du tableau en paramètre. \{\{nl\}\} Le `\{\{lang-c\}\}'\textbackslash{}0'` indique à printf où arrêter l'affichage des caractères. \tn % Row Count 12 (+ 12) % Row 15 \SetRowColor{white} `\{\{lang-c\}\}sprintf(name, "\%s \%d"," marion ", age);` & comme `\{\{lang-c\}\}printf()`, mais la chaîne est écrite dans `\{\{lang-c\}\}name` et non dans le terminal. \tn % Row Count 18 (+ 6) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Autres manipulation}}} \tn % Row Count 19 (+ 1) % Row 17 \SetRowColor{white} `\{\{lang-c\}\}char dest{[}10{]}="tic-", src{[}5{]}="toc";` \{\{nl\}\}`\{\{lang-c\}\}strcat(dest, src);` & Concaténation : ajoute à la fin de `\{\{lang-c\}\}dest`, le contenu de la chaîne `\{\{lang-c\}\}src` \tn % Row Count 24 (+ 5) % Row 18 \SetRowColor{LightBackground} `\{\{lang-c\}\}strcmp(dest, src);` & Comparaison : retourne 0 si le contenu de `\{\{lang-c\}\}dest` est identique au contenu de `\{\{lang-c\}\}src` \tn % Row Count 30 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Chaînes de caractères (Strings) (cont)}} \tn % Row 19 \SetRowColor{LightBackground} \textasciitilde{}\textasciitilde{}`\{\{lang-c\}\}dest == src`\textasciitilde{}\textasciitilde{} & (voir Tableaux pour plus de détail) Compare les adresses mémoire des 2 chaînes (toujours Faux) et non leur contenu. \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Une chaine de caractères (ou string) est un tableau contenant une suite de caractères, dont la fin de la suite est marquée par le caractère spécial `'\textbackslash{}0'`. \{\{nl\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{break9 (copy)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{\{\{counter\}\} Fichier texte}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{{\bf{Lecture d'un fichier}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{Un fichier texte à lire (la première ligne contient le nombre de données): \{\{nl\}\} 3 \{\{nl\}\}loic 65.3 \{\{nl\}\} marc 43.2 \{\{nl\}\} gerard 77.1} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Code correspondant: \{\{nl\}\}`\{\{lang-c\}\}File *f=NULL;` \{\{nl\}\} `\{\{lang-c\}\}double poids=0;` \{\{nl\}\} `\{\{lang-c\}\}int n=0;` \{\{nl\}\} `\{\{lang-c\}\}char name{[}30{]};` \{\{nl\}\} \{\{nl\}\}`\{\{lang-c\}\}f=fopen("file.txt","r");` \{\{nl\}\} `\{\{lang-c\}\}if (f==NULL) \{` \{\{nl\}\} `\{\{lang-c\}\} printf("error open\textbackslash{}n") ; return (-1);` \{\{nl\}\} `\{\{lang-c\}\}\}` \{\{nl\}\}`fscanf("\%d",\&n); /{\emph{lecture du nombre de ligne}}/` \{\{nl\}\} `while( fscanf(f, "\%s \%lf", name, \&poids ) != EOF) \{` \{\{nl\}\} `\{\{lang-c\}\} printf("\%s \%f", name, poids);`\{\{nl\}\} `\{\{lang-c\}\}\}`} \tn % Row Count 15 (+ 11) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{A chaque lecture ou écriture, la tête de lecture avance dans le fichier. On ne peut lire que sous la tête de lecture.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}