Skip to content
Snippets Groups Projects
Commit 5979bde4 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

corrected conflict

parents 9a1e3974 4a0c4b13
No related branches found
No related tags found
No related merge requests found
*.pdf
*.html
.vscode
......@@ -6,10 +6,6 @@ PDFOPTIONS += -V themeoptions:numbering=none -V themeoptions:progressbar=foot
PDFOPTIONS += -V fontsize=smaller
PDFOPTIONS += -V urlcolor=blue
HTMLOPTIONS = -t html5
HTMLOPTIONS += -c css/tufte-css/tufte.css
HTMLOPTIONS += --self-contained
REVEALOPTIONS = -t revealjs
REVEALOPTIONS += --self-contained
REVEALOPTIONS += -V revealjs-url=./reveal.js
......@@ -27,11 +23,10 @@ all: $(HTML) $(PDF)
%.html: %.md metadata.yaml
pandoc -s $(OPTIONS) $(REVEALOPTIONS) -o $@ $<
deploy: all all_html
deploy: all
mkdir -p prog_seq_c_cours
cp *.pdf prog_seq_c_cours
cp *.html prog_seq_c_cours
cp index.html prog_seq_c_cours/
clean:
rm -f *.pdf *.html
File moved
% Base I
% Inspirés des slides de F. Glück
% 16 septembre 2020
---
title: Base I
date: 16 septembre 2020
---
# Historique (1/2)
......
% Base II
% Inspirés des slides de F. Glück
% 23 septembre 2020
---
title: Base II
date: 23 septembre 2020
---
# Structures de contrôle: `switch`{.C} .. `case`{.C} (1/2)
......@@ -120,7 +121,7 @@ for (int i = 0; i != 1; i = rand() % 4) { // ésotérique
# Représentation des variables en mémoire (2/2)
![Les variables en mémoire.](figs/memory.svg){#fig:memory width=100%}
![Les variables en mémoire.](figs/memory.svg){width=100%}
# Les fonctions (1/7)
......
% Base III
% Inspirés des slides de F. Glück
% 30 septembre 2020
---
title: Base III
date: 30 septembre 2020
---
# Le C sur stackoverflow
......@@ -64,7 +65,7 @@
num->im = -1.0; // mémoire pas allouée.
```
![La représentation mémoire de `complex_t`.](figs/pointer_struct.svg){#fig:compilation width=100%}
![La représentation mémoire de `complex_t`.](figs/pointer_struct.svg){width=100%}
# Types complexes: `struct`{.C} (4/5)
......@@ -203,7 +204,7 @@
## Un seul fichier source
![Étapes de génération.](figs/compilation.svg){#fig:compilation width=100%}
![Étapes de génération.](figs/compilation.svg){width=100%}
# Génération d'un exécutable (2/5)
......@@ -224,7 +225,7 @@ Les différents codes intermédiaires sont effacés.
## Plusieurs fichiers sources
![Étapes de génération, plusieurs fichiers.](figs/compilation_plusieurs.svg){#fig:compilation_plusieurs width=100%}
![Étapes de génération, plusieurs fichiers.](figs/compilation_plusieurs.svg){width=100%}
# Génération d'un exécutable (4/5)
......
% Base IV
% Inspirés des slides de F. Glück
% 7 octobre 2020
---
title: Base IV
date: 7 octobre 2020
---
# Les tableaux (1/6)
......@@ -222,19 +223,19 @@ gcc -o example example.o
# Syntaxe d'un `Makefile` (1/4)
![Un exemple simple de `Makefile`.](figs/ex_makefile.svg){#fig:ex_makefile width=100%}
![Un exemple simple de `Makefile`.](figs/ex_makefile.svg){width=100%}
# Syntaxe d'un `Makefile` (2/4)
![La cible.](figs/ex_makefile_cible.svg){#fig:ex_makefile_cible width=100%}
![La cible.](figs/ex_makefile_cible.svg){width=100%}
# Syntaxe d'un `Makefile` (3/4)
![Les dépendances.](figs/ex_makefile_dep.svg){#fig:ex_makefile_dep width=100%}
![Les dépendances.](figs/ex_makefile_dep.svg){width=100%}
# Syntaxe d'un `Makefile` (4/4)
![La règle.](figs/ex_makefile_regle.svg){#fig:ex_makefile_regle width=100%}
![La règle.](figs/ex_makefile_regle.svg){width=100%}
# Principe de fonctionnement
......@@ -275,7 +276,7 @@ rebuild: clean hello
## Un graph complexe
![`Makefile` complexe.](figs/complex_makefile.svg){#fig:complex_makefile width=100%}
![`Makefile` complexe.](figs/complex_makefile.svg){width=100%}
:::
::::::::::::::
......
% Base V
% Inspirés des slides de F. Glück
% 14 octobre 2020
---
title: Base V
date: 14 octobre 2020
---
# Rappel: représentation des variables en mémoire
![Les variables en mémoire.](figs/memory.svg){#fig:memory width=100%}
![Les variables en mémoire.](figs/memory.svg){width=100%}
# Rappel: Les pointeurs (1/3)
......@@ -28,7 +29,7 @@
# Rappel: Les pointeurs (2/3)
![Les pointeurs, le déréférencement, et la mémoire.](figs/memory_deref.svg){#fig:memory width=100%}
![Les pointeurs, le déréférencement, et la mémoire.](figs/memory_deref.svg){width=100%}
# Rappel: Les pointeurs (3/3)
......@@ -128,7 +129,7 @@ p = &m; // erreur de compilation.
- La mémoire doit être désallouée explicitement $\Rightarrow$ **fuites mémoires**.
<!-- - Toujours garder un pointeur sur la mémoire allouée sinon **pointeur pendouillant**. -->
![La représentation mémoire de `complex_t` et fuites.](figs/pointer_struct_ok.svg){#fig:compilation width=100%}
![La représentation mémoire de `complex_t` et fuites.](figs/pointer_struct_ok.svg){width=100%}
# Allocation dynamique de mémoire (3/8)
......@@ -176,7 +177,7 @@ p = &m; // erreur de compilation.
## Arithmétique de pointeurs
![L'arithmétique des pointeurs.](figs/pointer_arithmetics.svg){#fig:compilation width=100%}
![L'arithmétique des pointeurs.](figs/pointer_arithmetics.svg){width=100%}
# Allocation dynamique de mémoire (6/8)
......@@ -195,7 +196,7 @@ p = &m; // erreur de compilation.
## Pointeur de pointeur
![L'arithmétique des pointeurs.](figs/double_pointeur.svg){#fig:compilation height=100%}
![L'arithmétique des pointeurs.](figs/double_pointeur.svg){height=100%}
# Allocation dynamique de mémoire (8/8)
......
% Base VI
% Inspirés des slides de F. Glück
% 28 octobre 2020
---
title: Base VI
date: 28 octobre 2020
---
# Types énumérés
......
base_7.md 0 → 100644
---
title: Base VII
date: 11 novembre 2020
---
# Les fichier en C
* Un fichier en C est représenté par un pointeur de fichier.
```C
#include <stdio.h>
FILE *fp;
```
* `FILE *`{.C} est une structure de donnée *opaque* contenant les informations sur l'état du fichier.
* Il est manipulé à l'aide de fonctions dédiées.
* Le pointeur de fichier est toujours passé *par référence*.
# Manipulations de fichier
* Pour lire/écrire dans un fichier il faut toujours effectuer trois étapes:
1. Ouvrir le fichier (`fopen()`{.C}).
2. Écrire/lire dans le fichier (`fgets()`{.C}, `fputs()`{.C}, `fread()`{.C}, `fwrite()`{.C}, ...).
3. Fermer le fichier (`fclose()`{.C}).
* Nous allons voir brièvement ces trois étapes.
# Ouverture d'un fichier
* L'ouverture d'un fichier se fait avec la fonction `fopen()`{.C}
```C
FILE *fp = fopen(filename, mode);
```
* `filename`{.C} est une chaîne de caractères (incluant le chemin).
* `mode`{.C} est le mode d'ouverture (`"r"`{.C}, `"w"`{.C}, ... voir `man 3 fopen`{.bash}) qui est une chaîne de caractères.
* Si l'ouverture échoue (pas la bonne permission, ou n'existe pas) `fopen()`{.C} retourne `0`.
* **Toujours** tester le retour de `fopen()`{.C}
```C
if (NULL == fp) {
fprintf(stderr, "Can't open output file %s!\n",
filename); // affiche dans le canal d'erreur
exit(RETURN_FAILURE);
}
```
# Fermeture d'un fichier
* Il faut **toujours** fermer un fichier à l'aide de `fclose()`{.C}
```C
FILE *fp = fopen("mon_fichier", "w");
// écritures diverses
fclose(fp);
```
* Les données sont transférées dans une mémoire tampon, puis dans le disques.
* Si la mémoire tampon est pleine, le fichier est fermé, ... les données sont écrites sur le disque.
* Si la mémoire tampon contient encore des données à la fin du programme les données sont **perdues**.
# Lecture d'un fichier (1/2)
```C
char *fgets(char *s, int size, FILE *stream)
```
* Lit une ligne de taille d'au plus `size-1` et la stocke dans `s`, depuis `stream`.
* Retourne `s` ou `NULL` si échoue.
```C
FILE *fp = fopen("text.txt", "r");
char buffer[100];
buffer = fgets(buffer, 37, fp);
// lit 36 caractères au plus et les écrit dans buffer
// s'arrête si rencontre EOF, ou "\n".
// ajoute un "\0" terminal
fclose(fp);
```
# Lecture d'un fichier (2/2)
```C
size_t fread(void *ptr, size_t size, size_t nmemb,
FILE *stream)
```
* Lit `nmemb` éléments de taille `size` octets et les écrit à l'adresse `ptr` dans le fichier `stream`.
* Retourne le nombre d'éléments lus.
```C
FILE *fp = fopen("doubles.bin", "rb");
double buffer[100];
size_t num = fread(buffer, sizeof(double), 4, fp);
// lit 4 double, se trouvant à l'adresse
// buffer dans le fichier fp au format binaire
// retourne 4
fclose(fp);
```
# Écriture dans un fichier (1/2)
```C
int fprintf(FILE *stream, const char *format, ...)
```
* Écrit la chaîne de caractères `format` dans le fichier stream.
* `format` a la même syntaxe que pour `printf()`.
* Retourne le nombre de caractères écrit sans le `\0` terminal(si réussite).
```C
FILE *fp = fopen("text.txt", "w");
fprintf(fp, "Hello world! We are in %d\n", 2020);
// Écrit "Hello world! We are in 2020"
// dans le fichier fp
fclose(fp);
```
# Écriture dans un fichier (2/2)
```C
size_t fwrite(const void *ptr, size_t size,
size_t nmemb, FILE *stream)
```
* Écrit `nmemb` éléments de taille `size` octets se trouvant à l'adresse `ptr` dans le fichier `stream`.
* Retourne le nombre d'éléments écrits.
```C
FILE *fp = fopen("doubles.bin", "wb");
double buffer[] = {1.0, 2.0, 3.0, 7.0};
size_t num = fwrite(buffer, sizeof(double), 4, fp);
// écrit 4 double, se trouvant à l'adresse
// buffer dans le fichier fp au format binaire
// retourne 4
fclose(fp);
```
# Les pointeurs de fichiers spéciaux
* Il existe trois `FILE *`{.C} qui existent pour tout programme:
* `stdin`{.C}: l'entrée standard.
* `stdout`{.C}: la sortie standard.
* `stderr`{.C}: l'erreur standard.
* Lors d'un fonctionnement dans le terminal:
* l'entrée standard est le *clavier*
* la sortie et erreur standard sont affichés dans le *terminal*.
* Ainsi on a
```C
fprintf(stdout, "texte\n"); // == printf("texte\n");
int a;
fscanf(stdin, "%d", &a); // == scanf("%d", &a);
```
......@@ -196,7 +196,7 @@ int main(void) {
# Représentation des variables en mémoire (2/N)
![Les variables en mémoire.](figs/memory.svg){#fig:memory width=100%}
![Les variables en mémoire.](figs/memory.svg){width=100%}
# Les pointeurs (1/N)
......@@ -220,7 +220,7 @@ int main(void) {
# Les pointeurs (2/N)
![Les pointeurs, le déréférencement, et la mémoire.](figs/memory_deref.svg){#fig:memory width=100%}
![Les pointeurs, le déréférencement, et la mémoire.](figs/memory_deref.svg){width=100%}
# Les pointeurs (3/N)
......@@ -318,7 +318,7 @@ int main(void) {
num->im = -1.0; // mémoire pas allouée.
```
![La représentation mémoire de `complex_t`.](figs/pointer_struct.svg){#fig:compilation width=100%}
![La représentation mémoire de `complex_t`.](figs/pointer_struct.svg){width=100%}
# Allocation dynamique de mémoire (1/N)
......@@ -345,7 +345,7 @@ int main(void) {
- La mémoire doit être désallouée explicitement $\Rightarrow$ **fuites mémoires**.
<!-- - Toujours garder un pointeur sur la mémoire allouée sinon **pointeur pendouillant**. -->
![La représentation mémoire de `complex_t` et fuites.](figs/pointer_struct_ok.svg){#fig:compilation width=100%}
![La représentation mémoire de `complex_t` et fuites.](figs/pointer_struct_ok.svg){width=100%}
# Allocation dynamique de mémoire (3/N)
......@@ -393,7 +393,7 @@ int main(void) {
## Arithmétique de pointeurs
![L'arithmétique des pointeurs.](figs/pointer_arithmetics.svg){#fig:compilation width=100%}
![L'arithmétique des pointeurs.](figs/pointer_arithmetics.svg){width=100%}
# Allocation dynamique de mémoire (6/N)
......@@ -413,7 +413,7 @@ int main(void) {
## Pointeur de pointeur
![L'arithmétique des pointeurs.](figs/double_pointeur.svg){#fig:compilation height=100%}
![L'arithmétique des pointeurs.](figs/double_pointeur.svg){height=100%}
# Allocation dynamique de mémoire (8/N)
......@@ -479,7 +479,7 @@ int main(void) {
## Un seul fichier source
![Étapes de génération.](figs/compilation.svg){#fig:compilation width=100%}
![Étapes de génération.](figs/compilation.svg){width=100%}
# Génération d'un exécutable (2/N)
......@@ -500,7 +500,7 @@ Les différents codes intermédiaires sont effacés.
## Plusieurs fichiers sources
![Étapes de génération, plusieurs fichiers.](figs/compilation_plusieurs.svg){#fig:compilation_plusieurs width=100%}
![Étapes de génération, plusieurs fichiers.](figs/compilation_plusieurs.svg){width=100%}
# Génération d'un exécutable (4/N)
......
......@@ -42,7 +42,7 @@ Ce qui marche *presque* tout le temps:
1. Appuyer sur le bouton `Super` (`Windows`) du clavier.
2. Commencer à taper "terminal".
![](figs/terminal_open.png){#fig:terminal_open width=100%}
![](figs/terminal_open.png){width=100%}
Raccourcis clavier:
......
......@@ -7,7 +7,7 @@
* Soit un ensemble de $N$ points $\mathcal{P}=\{p_i\}_{i=1}^N$.
* Une triangulation est un ensemble de triangle dont les sommets sont formés des points de $\mathcal{P}$ et couvrant leur envelope convexe.
![Deux exemples de triangulation (source: [wikipedia](https://bit.ly/2P2XCJ9)).](figs/PointSetTriangulations.svg){#fig:tri width=100%}
![Deux exemples de triangulation (source: [wikipedia](https://bit.ly/2P2XCJ9)).](figs/PointSetTriangulations.svg){width=100%}
## La triangulation de Delaunay
......@@ -28,27 +28,27 @@
## Exemple d'ajouts (1/6) (source [wikipedia](https://bit.ly/2vJs5p2))
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_0.png){#fig:tri width=100%}
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_0.png){width=100%}
## Exemple d'ajouts (2/6) (source [wikipedia](https://bit.ly/2vJs5p2))
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_1.png){#fig:tri width=100%}
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_1.png){width=100%}
## Exemple d'ajouts (3/6) (source [wikipedia](https://bit.ly/2vJs5p2))
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_2.png){#fig:tri width=100%}
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_2.png){width=100%}
## Exemple d'ajouts (4/6) (source [wikipedia](https://bit.ly/2vJs5p2))
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_3.png){#fig:tri width=100%}
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_3.png){width=100%}
## Exemple d'ajouts (5/6) (source [wikipedia](https://bit.ly/2vJs5p2))
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_4.png){#fig:tri width=100%}
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_4.png){width=100%}
## Exemple d'ajouts (6/6) (source [wikipedia](https://bit.ly/2vJs5p2))
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_6.png){#fig:tri width=100%}
![Ajout du premier point dans le super-triangle](figs/Bowyer-Watson_6.png){width=100%}
<!-- ## Pseudo-code de l'algorithme (1/2)
......
......@@ -17,7 +17,7 @@ Utilisez le libre service (l'horaire sera fixé prochainement).
Salon de discussion [Matrix](https://matrix.to/#/!tuZtXjUSPbnRfBsFXv:matrix.org?via=matrix.org), installez [element.io](https://element.io).
![](figs/matrix.png){#fig:memory width=20%}
![](figs/matrix.png){width=20%}
# Cyberlearn
......
......@@ -56,19 +56,19 @@ gcc -o example example.o
# Syntaxe d'un `Makefile` (1/4)
![Un exemple simple de `Makefile`.](figs/ex_makefile.svg){#fig:ex_makefile width=100%}
![Un exemple simple de `Makefile`.](figs/ex_makefile.svg){width=100%}
# Syntaxe d'un `Makefile` (2/4)
![La cible.](figs/ex_makefile_cible.svg){#fig:ex_makefile_cible width=100%}
![La cible.](figs/ex_makefile_cible.svg){width=100%}
# Syntaxe d'un `Makefile` (3/4)
![Les dépendances.](figs/ex_makefile_dep.svg){#fig:ex_makefile_dep width=100%}
![Les dépendances.](figs/ex_makefile_dep.svg){width=100%}
# Syntaxe d'un `Makefile` (4/4)
![La règle.](figs/ex_makefile_regle.svg){#fig:ex_makefile_regle width=100%}
![La règle.](figs/ex_makefile_regle.svg){width=100%}
# Principe de fonctionnement
......@@ -109,7 +109,7 @@ rebuild: clean hello
## Un graph complexe
![`Makefile` complexe.](figs/complex_makefile.svg){#fig:complex_makefile width=100%}
![`Makefile` complexe.](figs/complex_makefile.svg){width=100%}
:::
::::::::::::::
......
---
# used for lecture slides and homework sheets
subtitle: "Programmation séquentielle en C, 2020-2021"
author: "Orestis Malaspinas (A401), ISC, HEPIA"
institute: Inspirés des slides de F. Glück
lang: fr-CH
...
......@@ -21,7 +21,7 @@ $backgroundColor: #fff;
$mainColor: #222;
$headingColor: #222;
$mainFontSize: 25px;
$mainFontSize: 42px;
$mainFont: 'Source Sans Pro', Helvetica, sans-serif;
$headingFont: 'Source Sans Pro', Helvetica, sans-serif;
$headingTextShadow: none;
......@@ -32,15 +32,10 @@ $linkColor: #2a76dd;
$linkColorHover: lighten( $linkColor, 15% );
$selectionBackgroundColor: lighten( $linkColor, 25% );
$heading1Size: 2.0em;
$heading2Size: 1.7em;
$heading3Size: 1.4em;
$heading4Size: 1.1em;
// Vertical spacing between blocks of text
$blockMargin: 0px;
$headingMargin: 0 0 $blockMargin 0;
$heading1Size: 2.5em;
$heading2Size: 1.6em;
$heading3Size: 1.3em;
$heading4Size: 1.0em;
// Change text colors against dark slide backgrounds
@include dark-bg-text-color(#fff);
......
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -13,10 +13,10 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
:root {
--background-color: #fff;
--main-font: Source Sans Pro, Helvetica, sans-serif;
--main-font-size: 25px;
--main-font-size: 42px;
--main-color: #222;
--block-margin: 0px;
--heading-margin: 0 0 0px 0;
--block-margin: 20px;
--heading-margin: 0 0 20px 0;
--heading-font: Source Sans Pro, Helvetica, sans-serif;
--heading-color: #222;
--heading-line-height: 1.2;
......@@ -25,10 +25,10 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
--heading-text-shadow: none;
--heading-font-weight: 600;
--heading1-text-shadow: none;
--heading1-size: 2em;
--heading2-size: 1.7em;
--heading3-size: 1.4em;
--heading4-size: 1.1em;
--heading1-size: 2.5em;
--heading2-size: 1.6em;
--heading3-size: 1.3em;
--heading4-size: 1em;
--code-font: monospace;
--link-color: #2a76dd;
--link-color-hover: #6ca0e8;
......@@ -41,7 +41,7 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
.reveal {
font-family: "Source Sans Pro", Helvetica, sans-serif;
font-size: 25px;
font-size: 42px;
font-weight: normal;
color: #222; }
......@@ -69,7 +69,7 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
.reveal h4,
.reveal h5,
.reveal h6 {
margin: 0 0 0px 0;
margin: 0 0 20px 0;
color: #222;
font-family: "Source Sans Pro", Helvetica, sans-serif;
font-weight: 600;
......@@ -80,16 +80,16 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
word-wrap: break-word; }
.reveal h1 {
font-size: 2em; }
font-size: 2.5em; }
.reveal h2 {
font-size: 1.7em; }
font-size: 1.6em; }
.reveal h3 {
font-size: 1.4em; }
font-size: 1.3em; }
.reveal h4 {
font-size: 1.1em; }
font-size: 1em; }
.reveal h1 {
text-shadow: none; }
......@@ -98,7 +98,7 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
* OTHER
*********************************************/
.reveal p {
margin: 0px 0;
margin: 20px 0;
line-height: 1.3; }
/* Remove trailing margins after titles */
......@@ -160,7 +160,7 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
display: block;
position: relative;
width: 70%;
margin: 0px auto;
margin: 20px auto;
padding: 5px;
font-style: italic;
background: rgba(255, 255, 255, 0.05);
......@@ -177,7 +177,7 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
display: block;
position: relative;
width: 90%;
margin: 0px auto;
margin: 20px auto;
text-align: left;
font-size: 0.55em;
font-family: monospace;
......@@ -240,7 +240,7 @@ section.has-dark-background, section.has-dark-background h1, section.has-dark-ba
vertical-align: top; }
.reveal img {
margin: 0px 0; }
margin: 20px 0; }
/*********************************************
* LINKS
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment