This commit is contained in:
Simoes Lukas
2025-01-07 15:07:12 +01:00
parent f7764aa296
commit 59f7eead89
21 changed files with 475 additions and 16 deletions

24
DEV1.1/CM2/Makefile Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View File

@@ -0,0 +1,6 @@
# include <stdio.h>
int main(void) {
printf("Hello world\n");
return EXIT_SUCCESS;
}