Ajout des travaux effectuer

This commit is contained in:
2024-12-09 11:53:11 +01:00
parent 05fac8d3ae
commit c4e97e13da
558 changed files with 67900 additions and 0 deletions

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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

View 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;
}

View File

@@ -0,0 +1,8 @@
#ifndef REPETITION_H
#define REPETITION_H
#include <stdbool.h>
bool sont_identiques(const long tableau[], int taille);
#endif

Binary file not shown.

View 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;
}

Binary file not shown.

View File

@@ -0,0 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
struct timespec tim, tim2;
tim.tv_sec = 1;
tim.tv_nsec = 2;
if(nanosleep(&tim , &tim2) < 0 )
{
printf("Nano sleep system call failed \n");
return -1;
}
printf("ERREUR\n");
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,21 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
int main(void)
{
struct timeval start, end;
double result;
int i;
gettimeofday(&start,NULL);
for(i = 0 ; i<1000000 ; i++){
result = sqrt(2.0);
}
gettimeofday(&end,NULL);
long elapsed_time = (end.tv_sec-start.tv_sec)*1000000+(end.tv_usec-start.tv_usec);
printf("%ldµs\n",elapsed_time);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,29 @@
#include <stdlib.h>
#include <stdio.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(void)
{
const char *nomFichier = "image";
afficherImage(nomFichier);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,35 @@
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
FILE* fi1 = fopen(argv[1],"r");
FILE* fi2 = fopen(argv[2],"r");
char space1[91];
char space2[91];
int diff = 0;
if(argc<3){
fprintf(stderr,"erreur ! Le format doit etre sous forme : %s <fichier1> <fichier2>\n", argv[0]);
return EXIT_FAILURE;
}
if(fi1 == NULL || fi2 == NULL){
fprintf(stderr,"un des dossiers est indisponible !\n");
return EXIT_FAILURE;
}
while(!feof(fi1)&&!feof(fi2)){
fread(space1,1,1,fi1);
fread(space2,1,1,fi2);
if(space1[91] == space2[91]){
diff++;
}
}
printf("%d\n", diff);
if(diff>0){
printf("Fichiers identiques\n");
}else{
printf("Fichiers non identiques\n");
}
fclose(fi1);
fclose(fi2);
return EXIT_SUCCESS;
}

BIN
23DEV1.1/TPS1/TP2/controle/a.out Executable file

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("%d\n", 72);
printf("%d\n", 0110);
printf("%d\n", 72);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("%d\n", 72);
printf("%d\n", 0110);
printf("%d\n", 0x48);
return EXIT_SUCCESS;
}