Ajout des TP

This commit is contained in:
stiti
2024-02-01 13:55:03 +01:00
parent 4fe273c309
commit 113583b37a
228 changed files with 7094 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
### VARIABLES ###
CC = gcc
CFLAGS = -ansi \
-pedantic
EXE = valeurs_nulles
OFILES = recherche.o \
main.o
### BUT PAR DEFAUT ###
but : ${EXE}
### REGLES ESSENTIELLES ###
recherche.o : recherche.c
main.o : main.c recherche.h
${EXE} : ${OFILES}
$(CC) $(CFLAGS) -o ${EXE} ${OFILES}
### REGLES OPTIONNELLES ###
clean :
-rm -f ${OFILES}
mrproper : clean but
### BUTS FACTICES ###
.PHONY : but clean mrproper
### FIN ###

View File

@@ -0,0 +1,15 @@
#include <stdlib.h>
#include <stdio.h>
#include "recherche.h"
int main(int argc, char* argv[]){ /* ou char** */
int i;
double* tab;
tab = (double*) malloc(argc*sizeof(double));
for(i=0;i<argc-1;i++){
tab[i] = strtod(argv[i+1],NULL);
}
printf("%d valeurs nulles\n",recherche(tab,argc-1));
}

View File

@@ -0,0 +1,13 @@
#include <stdlib.h>
#include <stdio.h>
int recherche(double tab[], int taille){
int valeurs_null = 0, i;
for(i=0;i<taille;i++){
if(tab[i]==0){
valeurs_null++;
}
}
return valeurs_null;
}

View File

@@ -0,0 +1,6 @@
#ifndef RECHERCHE_H
#define RECHERCHE_h
int recherche(double tab[], int taille);
#endif /* RECHERCHE_H */

Binary file not shown.

View File

@@ -0,0 +1,41 @@
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[]){
char donnees_fichier1, donnees_fichier2;
int reponse = 1;
FILE* fichier1 = fopen(argv[1],"r");
FILE* fichier2 = fopen(argv[2],"r");
/* Message d'erreur s'il manque des arguments // s'il y a trop d'arguments */
if(argc != 3){
fputs("Erreur : Le nombre d'arguments est incorrect !\n",stderr);
return EXIT_FAILURE;
}
if(fichier1 == NULL){
fputs("Erreur : Impossible d'accéder au fichier 1\n",stderr);
return EXIT_FAILURE;
}
if(fichier2 == NULL){
fputs("Erreur : Impossible d'accéder au fichier 2\n",stderr);
return EXIT_FAILURE;
}
while(feof(fichier1)!=1 && feof(fichier1)!=1){
fread(&donnees_fichier1,1,1,fichier1);
fread(&donnees_fichier2,1,1,fichier2);
if(donnees_fichier1 != donnees_fichier2){
printf("Fichiers pas identiques !\n");
reponse = 0;
break;
}
}
if(reponse == 1){
printf("Fichiers identiques !\n");
}
fclose(fichier1);
fclose(fichier2);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,5 @@
#include <stdlib.h>
int main(void){
}

View File

@@ -0,0 +1,5 @@
#include <stdlib.h>
int main(void){
int a;
}

View File

@@ -0,0 +1,21 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void){
struct timespec req;
req.tv_sec = 0;
req.tv_nsec = 500000000; /* 0.5 secondes*/
fputs("E",stderr);
nanosleep(&req,NULL);
fputs("R",stderr);
nanosleep(&req,NULL);
fputs("R",stderr);
nanosleep(&req,NULL);
fputs("E",stderr);
nanosleep(&req,NULL);
fputs("U",stderr);
nanosleep(&req,NULL);
fputs("R",stderr);
}