Ajout des travaux effectuer
This commit is contained in:
31
23DEV1.1/TPS1/TP2/controle/CM2_2022/2Representation.c
Normal file
31
23DEV1.1/TPS1/TP2/controle/CM2_2022/2Representation.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void afficherImage(const char *nomFichier) {
|
||||
FILE *fichier = fopen(nomFichier, "rb");
|
||||
int couleur;
|
||||
|
||||
|
||||
if (fichier == NULL) {
|
||||
perror("Erreur lors de l'ouverture du fichier");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (fread(&couleur, 1, 1, fichier) == 1) {
|
||||
if (couleur == 0) {
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("\33[48;5;%dm \33[m", couleur);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fichier);
|
||||
}
|
||||
|
||||
int main() {
|
||||
const char *nomFichier = "image";
|
||||
|
||||
afficherImage(nomFichier);
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
23DEV1.1/TPS1/TP2/controle/CM2_2022/2Reproduction.c
Normal file
53
23DEV1.1/TPS1/TP2/controle/CM2_2022/2Reproduction.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int compare_fichiers(const char *nom_fichier1, const char *nom_fichier2) {
|
||||
FILE *fichier1 = fopen(nom_fichier1, "rb");
|
||||
FILE *fichier2 = fopen(nom_fichier2, "rb");
|
||||
|
||||
if (fichier1 == NULL || fichier2 == NULL) {
|
||||
perror("Erreur lors de l'ouverture des fichiers");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int caractere1, caractere2;
|
||||
|
||||
while (1) {
|
||||
caractere1 = fgetc(fichier1);
|
||||
caractere2 = fgetc(fichier2);
|
||||
|
||||
if (caractere1 != caractere2) {
|
||||
fclose(fichier1);
|
||||
fclose(fichier2);
|
||||
return 0; /*Les fichiers ne sont pas identiques*/
|
||||
}
|
||||
|
||||
if (caractere1 == EOF) {
|
||||
break; /*Fin des fichiers*/
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fichier1);
|
||||
fclose(fichier2);
|
||||
|
||||
return 1; /*Les fichiers sont identiques*/
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s <fichier1> <fichier2>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int resultat = compare_fichiers(argv[1], argv[2]);
|
||||
|
||||
if (resultat == 1) {
|
||||
printf("Fichiers identiques !\n");
|
||||
} else if (resultat == 0) {
|
||||
printf("Fichiers non identiques !\n");
|
||||
} else {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
25
23DEV1.1/TPS1/TP2/controle/CM2_2022/3Ralenti.c
Normal file
25
23DEV1.1/TPS1/TP2/controle/CM2_2022/3Ralenti.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
int main() {
|
||||
const char* mot = "ERREUR";
|
||||
struct timespec attente;
|
||||
int i;
|
||||
|
||||
attente.tv_sec = 0;
|
||||
attente.tv_nsec = 500000000;
|
||||
|
||||
for (i = 0; i < strlen(mot); i++) {
|
||||
putchar(mot[i]);
|
||||
fflush(stdout);
|
||||
if (nanosleep(&attente, NULL) == -1) {
|
||||
perror("nanosleep");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
||||
27
23DEV1.1/TPS1/TP2/controle/CM2_2022/3Rapidite.c
Normal file
27
23DEV1.1/TPS1/TP2/controle/CM2_2022/3Rapidite.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int main() {
|
||||
struct timeval start, end;
|
||||
double result;
|
||||
|
||||
/*Enregistrez le temps de début*/
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
/* Effectuez le calcul un million de fois */
|
||||
int i;
|
||||
for (i = 0; i < 1000000; ++i) {
|
||||
result = sqrt(2.0);
|
||||
}
|
||||
|
||||
/* Enregistrez le temps de fin */
|
||||
gettimeofday(&end, NULL);
|
||||
|
||||
/* Calculez le temps écoulé en microsecondes */
|
||||
long elapsed_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
|
||||
|
||||
printf("%ldμs\n", elapsed_time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
35
23DEV1.1/TPS1/TP2/controle/CM2_2022/Makefile
Normal file
35
23DEV1.1/TPS1/TP2/controle/CM2_2022/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
#BUT FINAL
|
||||
|
||||
all : Repetition exo3
|
||||
|
||||
#Variables
|
||||
|
||||
OFILES = main.o \
|
||||
Repetition.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -ansi -pedantic
|
||||
|
||||
#Dépendances
|
||||
|
||||
main.o: main.c Repetition.h
|
||||
|
||||
Repetition.o: Repetition.c Repetition.h
|
||||
|
||||
#Exec
|
||||
|
||||
Repetition: $(OFILES)
|
||||
$(CC) $(CFLAGS) -o Repetition $(OFILES) && rm -f *.o && echo "Utilisation : ./Repetition"
|
||||
|
||||
exo3 : 3Ralenti.c
|
||||
$(CC) $(CFLAGS) -std=gnu99 -o exo3 3Ralenti.c && echo "Utilisation : ./exo3"
|
||||
|
||||
#Nettoyage
|
||||
|
||||
clean:
|
||||
rm -f Repetition && rm -f exo3
|
||||
|
||||
#But factice
|
||||
|
||||
.PHONY : but clean
|
||||
12
23DEV1.1/TPS1/TP2/controle/CM2_2022/Repetition.c
Normal file
12
23DEV1.1/TPS1/TP2/controle/CM2_2022/Repetition.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdbool.h>
|
||||
#include "Repetition.h"
|
||||
|
||||
bool sont_identiques(const long tableau[], int taille) {
|
||||
int i;
|
||||
for (i = 1; i < taille; ++i) {
|
||||
if (tableau[i] != tableau[0]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
8
23DEV1.1/TPS1/TP2/controle/CM2_2022/Repetition.h
Normal file
8
23DEV1.1/TPS1/TP2/controle/CM2_2022/Repetition.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef REPETITION_H
|
||||
#define REPETITION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool sont_identiques(const long tableau[], int taille);
|
||||
|
||||
#endif
|
||||
BIN
23DEV1.1/TPS1/TP2/controle/CM2_2022/image
Normal file
BIN
23DEV1.1/TPS1/TP2/controle/CM2_2022/image
Normal file
Binary file not shown.
38
23DEV1.1/TPS1/TP2/controle/CM2_2022/main.c
Normal file
38
23DEV1.1/TPS1/TP2/controle/CM2_2022/main.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "Repetition.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int taille = argc - 1;
|
||||
int i;
|
||||
long *tableau = malloc(taille * sizeof(long));
|
||||
bool resultat = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <entiers...>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!tableau) {
|
||||
perror("Erreur d'allocation de mémoire");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
tableau[i - 1] = strtol(argv[i], NULL, 10);
|
||||
}
|
||||
|
||||
resultat = sont_identiques(tableau, taille);
|
||||
|
||||
if (resultat) {
|
||||
printf("valeurs identiques\n");
|
||||
} else {
|
||||
printf("valeurs non identiques\n");
|
||||
}
|
||||
|
||||
free(tableau);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
BIN
23DEV1.1/TPS1/TP2/controle/CM2_2022/test
Executable file
BIN
23DEV1.1/TPS1/TP2/controle/CM2_2022/test
Executable file
Binary file not shown.
Reference in New Issue
Block a user