A
This commit is contained in:
parent
f7764aa296
commit
59f7eead89
24
DEV1.1/CM2/Makefile
Normal file
24
DEV1.1/CM2/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
CC = gcc
|
||||
CFLAGS = -ansi \
|
||||
-pedantic
|
||||
EXE = final
|
||||
OFILES = moyenne.o \
|
||||
moyenne_main.o
|
||||
|
||||
### BUT PAR DEFAUT ###
|
||||
|
||||
final : ${EXE}
|
||||
|
||||
### REGLES ESSENTIELLES ###
|
||||
|
||||
moyenne_main.o : moyenne_main.c
|
||||
|
||||
moyenne.o : moyenne.h moyenne.c
|
||||
|
||||
${EXE} : ${OFILES}
|
||||
$(CC) $(CFLAGS) -o ${EXE} ${OFILES}
|
||||
|
||||
### REGLES OPTIONNELLES ###
|
||||
|
||||
clean :
|
||||
-rm -f ${OFILES} ${EXE}
|
23
DEV1.1/CM2/melange.c
Normal file
23
DEV1.1/CM2/melange.c
Normal file
@ -0,0 +1,23 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
FILE* fichier = NULL;
|
||||
char premier_octet;
|
||||
char resultat;
|
||||
if (argc != 2) {
|
||||
printf("Pas de fichier à modifier.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fichier = fopen(argv[1], "r");
|
||||
if (fichier == NULL) {
|
||||
printf("Erreur d'ouverture.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fread(&premier_octet, 1, 1, fichier);
|
||||
fclose(fichier);
|
||||
fichier = fopen(argv[1], "a+");
|
||||
/* Pas fini */
|
||||
fclose(fichier);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
10
DEV1.1/CM2/mesure.c
Normal file
10
DEV1.1/CM2/mesure.c
Normal file
@ -0,0 +1,10 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <sys/stat.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
struct stat a;
|
||||
stat(argv[1], &a);
|
||||
printf("%jd octets\n", a.st_size);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
69
DEV1.1/CM2/moderation.c
Normal file
69
DEV1.1/CM2/moderation.c
Normal file
@ -0,0 +1,69 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
struct mail {
|
||||
double x;
|
||||
double y;
|
||||
struct mail* suivant;
|
||||
};
|
||||
|
||||
typedef struct mail maillon;
|
||||
|
||||
void afficher_liste(maillon* liste) {
|
||||
maillon* p;
|
||||
for (p = liste; p != NULL; p = p->suivant) {
|
||||
printf("(%.1f, %.1f) -> ", p->x, p->y);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
maillon* creation_liste(void) {
|
||||
int i;
|
||||
maillon* p;
|
||||
maillon* premier;
|
||||
maillon* s;
|
||||
srand(time(NULL));
|
||||
premier = (maillon*) malloc(sizeof(maillon));
|
||||
if (!premier) {
|
||||
printf("Erreur d'allocation mémoire. (1) \n");
|
||||
}
|
||||
premier->x = -12; /* Le premier maillon sera toujours négatif, les autres seront aléatoires */
|
||||
premier->y = -3;
|
||||
p = premier;
|
||||
for (i = 0; i != 4; i++) {
|
||||
s = (maillon*) malloc(sizeof(maillon));
|
||||
if (!s) {
|
||||
printf("Erreur d'allocation mémoire. (2) \n");
|
||||
}
|
||||
s->x = (rand() % 50) - 25;
|
||||
s->y = (rand() % 50) - 25;
|
||||
p->suivant = s;
|
||||
p = s;
|
||||
}
|
||||
return premier;
|
||||
}
|
||||
|
||||
maillon* supprime_coord_negatives(maillon* liste) {
|
||||
maillon* p;
|
||||
maillon* premier = liste;
|
||||
maillon* precedent = liste;
|
||||
for (p = liste; p != NULL; p = p->suivant) {
|
||||
if ((p->x) < 0.0 && (p->y) < 0.0) {
|
||||
p = precedent;
|
||||
p->suivant = p->suivant->suivant;
|
||||
precedent = p;
|
||||
p = p->suivant;
|
||||
}
|
||||
else {
|
||||
precedent = p;
|
||||
}
|
||||
}
|
||||
return premier;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
maillon* liste = creation_liste();
|
||||
afficher_liste(liste);
|
||||
afficher_liste(supprime_coord_negatives(liste));
|
||||
return EXIT_SUCCESS;
|
||||
}
|
8
DEV1.1/CM2/moyenne.c
Normal file
8
DEV1.1/CM2/moyenne.c
Normal file
@ -0,0 +1,8 @@
|
||||
double moyenne(int* t, int len) {
|
||||
int i;
|
||||
int somme = 0;
|
||||
for (i = 0; i != len; i++) {
|
||||
somme += t[i];
|
||||
}
|
||||
return somme/len;
|
||||
}
|
6
DEV1.1/CM2/moyenne.h
Normal file
6
DEV1.1/CM2/moyenne.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef MOYENNE
|
||||
#define MOYENNE
|
||||
|
||||
double moyenne(int* t, int len);
|
||||
|
||||
#endif
|
14
DEV1.1/CM2/moyenne_main.c
Normal file
14
DEV1.1/CM2/moyenne_main.c
Normal file
@ -0,0 +1,14 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include "moyenne.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i;
|
||||
int* t = malloc(sizeof(int)*argc);
|
||||
for (i = 0; i != argc-1; i++) {
|
||||
t[i] = (int) strtol(argv[i+1], NULL, 10);
|
||||
}
|
||||
printf("Moyenne : %.2f\n", moyenne(t, argc-1));
|
||||
free(t);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
6
DEV1.1/CM2/toto.c
Normal file
6
DEV1.1/CM2/toto.c
Normal file
@ -0,0 +1,6 @@
|
||||
# include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
printf("Hello world\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
DEV1.1/Entrainements/controle_machine_2_A/reitne
Normal file
BIN
DEV1.1/Entrainements/controle_machine_2_A/reitne
Normal file
Binary file not shown.
@ -1,11 +1,27 @@
|
||||
carre: carre.o hue.o
|
||||
gcc -ansi -pedantic -o carre carre.o hue.o
|
||||
CC = gcc
|
||||
CFLAGS = -ansi \
|
||||
-pedantic
|
||||
EXE = but
|
||||
OFILES = carre.o \
|
||||
hue.o
|
||||
|
||||
### BUT PAR DEFAUT ###
|
||||
|
||||
but : ${EXE}
|
||||
|
||||
### REGLES ESSENTIELLES ###
|
||||
|
||||
carre.o : carre.c
|
||||
gcc -ansi -pedantic -c carre.c
|
||||
|
||||
hue.o : hue.c hue.h
|
||||
gcc -ansi -pedantic -c hue.c
|
||||
hue.o : hue.h hue.c
|
||||
|
||||
run : carre
|
||||
./carre
|
||||
${EXE} : ${OFILES}
|
||||
$(CC) $(CFLAGS) -o ${EXE} ${OFILES}
|
||||
|
||||
### REGLES OPTIONNELLES ###
|
||||
|
||||
run : but
|
||||
./${EXE}
|
||||
|
||||
clean :
|
||||
-rm -f ${OFILES} ${EXE}
|
BIN
DEV1.1/Entrainements/controle_machine_2_B/but
Executable file
BIN
DEV1.1/Entrainements/controle_machine_2_B/but
Executable file
Binary file not shown.
@ -1,4 +1,6 @@
|
||||
#include "carre.c"
|
||||
#define RED 1
|
||||
#define GREEN 2
|
||||
#define BLUE 4
|
||||
|
||||
int hue(void) {
|
||||
int choice = rand()%3;
|
||||
|
@ -1,13 +1,21 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
int f(int n) {
|
||||
if (n>100)
|
||||
return n-10;
|
||||
else
|
||||
return f(f(n+11));
|
||||
void sierpinski(unsigned int n) {
|
||||
if (n == 0) {
|
||||
DessinerSegment(100,800,800,800);
|
||||
DessinerSegment(450,100,100,800);
|
||||
DessinerSegment(450,100,800,800);
|
||||
}
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
f(12);
|
||||
int main(int argc, char** argv) {
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(200, 200, 900, 900);
|
||||
sierpinski((int) strtol(argv[1], NULL, 10));
|
||||
while (1) {
|
||||
/* Infini */
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
4
DEV1.1/TP29/TP29_reponses.txt
Normal file
4
DEV1.1/TP29/TP29_reponses.txt
Normal file
@ -0,0 +1,4 @@
|
||||
----- TP29 : Piles -----
|
||||
|
||||
1.
|
||||
|
50
DEV1.1/TP29/test.c
Normal file
50
DEV1.1/TP29/test.c
Normal file
@ -0,0 +1,50 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
struct maillon_s {
|
||||
char valeur;
|
||||
struct maillon_s* suivant;
|
||||
};
|
||||
|
||||
typedef struct maillon_s pile;
|
||||
|
||||
|
||||
void push(pile* p, char c) {
|
||||
pile* s = p;
|
||||
s = (pile*) malloc(sizeof(pile));
|
||||
p->valeur = c;
|
||||
p->suivant = s;
|
||||
}
|
||||
|
||||
int empty(pile* p) {
|
||||
return (p == NULL);
|
||||
}
|
||||
|
||||
|
||||
char pop(pile* p) {
|
||||
if (!empty) {
|
||||
pile* s = p;
|
||||
free(p);
|
||||
return s->valeur;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void affiche_pile(pile* p) {
|
||||
pile* s;
|
||||
for (s = p; s->suivant != NULL; s = s->suivant) {
|
||||
printf("| %c |\n", s->valeur);
|
||||
}
|
||||
printf("-----\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
pile* p;
|
||||
push(p, 'A');
|
||||
affiche_pile(p);
|
||||
push(p, 'B');
|
||||
affiche_pile(p);
|
||||
push(p, 'C');
|
||||
affiche_pile(p);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
4
DEV1.1/TP30/TP30_reponses.txt
Normal file
4
DEV1.1/TP30/TP30_reponses.txt
Normal file
@ -0,0 +1,4 @@
|
||||
----- TP30 : Files -----
|
||||
|
||||
1.
|
||||
|
153
DEV1.1/TP30/test.c
Normal file
153
DEV1.1/TP30/test.c
Normal file
@ -0,0 +1,153 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <graph.h>
|
||||
|
||||
typedef struct {
|
||||
char valeurs[100];
|
||||
int debut;
|
||||
int fin;
|
||||
size_t taille;
|
||||
} file;
|
||||
|
||||
void initialise_file(file* f) {
|
||||
f->debut = 0;
|
||||
f->fin = 0;
|
||||
f->taille = 0;
|
||||
}
|
||||
|
||||
int empty(file* f) {
|
||||
return (f->taille == 0);
|
||||
}
|
||||
|
||||
void enqueue(file* f, char c) {
|
||||
f->valeurs[f->fin] = c;
|
||||
f->fin++;
|
||||
f->taille++;
|
||||
}
|
||||
|
||||
char dequeue(file* f) {
|
||||
if (empty(f)) {
|
||||
printf("Erreur : La file est vide.\n");
|
||||
return;
|
||||
}
|
||||
f->debut++;
|
||||
f->taille--;
|
||||
return f->valeurs[f->debut-1];
|
||||
}
|
||||
|
||||
|
||||
void affiche_file(file* f) {
|
||||
int i;
|
||||
if (f->taille == 0) {
|
||||
printf("File vide.\n");
|
||||
return;
|
||||
}
|
||||
printf("<------------\n");
|
||||
for (i = f->debut; i != f->fin; i++) {
|
||||
if (i == 100) {
|
||||
i = 0;
|
||||
}
|
||||
printf("%c ",f->valeurs[i]);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
char first(file* f) {
|
||||
return f->valeurs[f->debut];
|
||||
}
|
||||
|
||||
void clear(file* f) {
|
||||
while (!empty(f)) {
|
||||
dequeue(f);
|
||||
}
|
||||
}
|
||||
|
||||
void affiche_couleurs(void) {
|
||||
ChoisirCouleurDessin(CouleurParComposante(16,217,62)); /* Green */
|
||||
RemplirRectangle(0,0,400,400);
|
||||
ChoisirCouleurDessin(CouleurParComposante(245,14,14)); /* Red */
|
||||
RemplirRectangle(400,0,400,400);
|
||||
ChoisirCouleurDessin(CouleurParComposante(221,220,28)); /* Yellow */
|
||||
RemplirRectangle(0,400,400,400);
|
||||
ChoisirCouleurDessin(CouleurParComposante(28,95,221)); /* Blue */
|
||||
RemplirRectangle(400,400,400,400);
|
||||
}
|
||||
|
||||
void choisit_couleur_aleatoire(file* f) {
|
||||
/* Met en valeur une couleur graphiquement et stocke la
|
||||
couleur dans la file avec l'initiale de la couleur */
|
||||
int x,y;
|
||||
unsigned long ms = Microsecondes();
|
||||
unsigned long cycle = 1000000L;
|
||||
while (ms + cycle < Microsecondes())
|
||||
srand(time(NULL));
|
||||
x = rand() % 800;
|
||||
y = rand() % 800;
|
||||
if (x < 400 && y < 400) {
|
||||
enqueue(f, 'G');
|
||||
ChoisirCouleurDessin(CouleurParNom("green"));
|
||||
RemplirRectangle(0,0,400,400);
|
||||
}
|
||||
else if (x > 400 && y < 400) {
|
||||
enqueue(f, 'R');
|
||||
ChoisirCouleurDessin(CouleurParNom("red"));
|
||||
RemplirRectangle(400,0,400,400);
|
||||
}
|
||||
else if (x < 400 && y > 400) {
|
||||
enqueue(f, 'Y');
|
||||
ChoisirCouleurDessin(CouleurParNom("yellow"));
|
||||
RemplirRectangle(0,400,400,400);
|
||||
}
|
||||
else if (x > 400 && y > 400) {
|
||||
enqueue(f, 'B');
|
||||
ChoisirCouleurDessin(CouleurParNom("blue"));
|
||||
RemplirRectangle(400,400,400,400);
|
||||
}
|
||||
else {
|
||||
printf("ERREUR");
|
||||
}
|
||||
ms = Microsecondes() + cycle;
|
||||
while (Microsecondes() < ms) {
|
||||
/* Attente 1sec */
|
||||
}
|
||||
affiche_couleurs();
|
||||
}
|
||||
|
||||
char choix_utilisateur(void) {
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int nb_tours = 1;
|
||||
file f;
|
||||
initialise_file(&f);
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(200,100,800,800);
|
||||
affiche_couleurs();
|
||||
while (1) {
|
||||
choisit_couleur_aleatoire(&f);
|
||||
affiche_file(&f);
|
||||
while (empty(f)) {
|
||||
char couleur;
|
||||
char choix;
|
||||
couleur = dequeue(f);
|
||||
choix = choix_utilisateur();
|
||||
}
|
||||
/* Boucle infinie */
|
||||
}
|
||||
/*affiche_file(f);
|
||||
enqueue(f, 'A');
|
||||
enqueue(f, 'B');
|
||||
enqueue(f, 'C');
|
||||
affiche_file(f);
|
||||
dequeue(f);
|
||||
affiche_file(f);
|
||||
dequeue(f);
|
||||
affiche_file(f);
|
||||
enqueue(f, 'D');
|
||||
affiche_file(f);
|
||||
clear(f);
|
||||
affiche_file(f);*/
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
0
DEV1.1/TP31/TP31_reponses.txt
Normal file
0
DEV1.1/TP31/TP31_reponses.txt
Normal file
61
DEV1.1/TP31/test.c
Normal file
61
DEV1.1/TP31/test.c
Normal file
@ -0,0 +1,61 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum wedge {
|
||||
PITCHING = 1,
|
||||
GAP = 2,
|
||||
SAND = 3,
|
||||
LOP = 4,
|
||||
FLIP = 5
|
||||
};
|
||||
|
||||
enum putter {
|
||||
REGULAR = 1,
|
||||
BELLY = 2,
|
||||
LONG = 3
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
char* marque;
|
||||
char* modele;
|
||||
char* categorie;
|
||||
unsigned int sous_categorie : 4;
|
||||
} club;
|
||||
|
||||
void affiche_catalogue(int taille_catalogue, club* catalogue) {
|
||||
int i;
|
||||
char* wedge[5] = {"Pitching", "Gap", "Sand", "Lop", "Flip"};
|
||||
char* putter[3] = {"Regular", "Belly", "Long"};
|
||||
printf("| Marque | Modèle | Catégorie | Sous-catégorie |\n");
|
||||
printf("------------------------------------------------\n");
|
||||
for (i = 0; i != taille_catalogue; i++) {
|
||||
printf("| %6s | %6s | %9s | %14d |\n", catalogue[i].marque, catalogue[i].modele, catalogue[i].categorie, catalogue[i].sous_categorie);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int i;
|
||||
club catalogue[10];
|
||||
char* marques[4] = {"A", "B", "C", "D"};
|
||||
char* modeles[4] = {"M", "N", "O", "P"};
|
||||
char* categories[4] = {"Bois", "Fer", "Wedge", "Putter"};
|
||||
srand(time(NULL));
|
||||
for(i = 0; i != 10; i++) {
|
||||
catalogue[i].marque = marques[rand() % 4];
|
||||
catalogue[i].modele = modeles[rand() % 4];
|
||||
catalogue[i].categorie = categories[rand() % 4];
|
||||
if (catalogue[i].categorie == "Wedge") {
|
||||
catalogue[i].sous_categorie = rand() % 5;
|
||||
}
|
||||
else if (catalogue[i].categorie == "Putter") {
|
||||
catalogue[i].sous_categorie = rand() % 3;
|
||||
}
|
||||
else {
|
||||
catalogue[i].sous_categorie = rand() % 9 + 1;
|
||||
}
|
||||
}
|
||||
affiche_catalogue(10, catalogue);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
1
DEV1.1/commande_grep
Normal file
1
DEV1.1/commande_grep
Normal file
@ -0,0 +1 @@
|
||||
grep --color -E '[[:digit:]]+(\.[[:digit:]]+)?[[:blank:]]+\*[[:blank:]]+[[:digit:]]+(\.[[:digit:]])+(\.[[:digit:]]*)?' sensors.conf
|
BIN
DEV1.1/simoes_CM2.tar.gz
Normal file
BIN
DEV1.1/simoes_CM2.tar.gz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user