Ajout des TP
This commit is contained in:
5
BUT1/DEV1.1/CM2_2/.vscode/extensions.json
vendored
Normal file
5
BUT1/DEV1.1/CM2_2/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"bito.bito"
|
||||
]
|
||||
}
|
5
BUT1/DEV1.1/CM2_2/.vscode/settings.json
vendored
Normal file
5
BUT1/DEV1.1/CM2_2/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"stdlib.h": "c"
|
||||
}
|
||||
}
|
13
BUT1/DEV1.1/CM2_2/CM2/Makefile
Normal file
13
BUT1/DEV1.1/CM2_2/CM2/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
carre : carre.o lightness.o
|
||||
gcc -ansi -pedantic -o carre carre.o lightness.o
|
||||
|
||||
lightness.o : lightness.c
|
||||
gcc -ansi -pedantic -c lightness.c
|
||||
|
||||
carre.o : carre.c lightness.h
|
||||
gcc -ansi -pedantic -c carre.c
|
||||
|
||||
clean :
|
||||
rm -f carre.o lightness.o
|
||||
|
||||
.PHONY : clean
|
BIN
BUT1/DEV1.1/CM2_2/CM2/carre
Executable file
BIN
BUT1/DEV1.1/CM2_2/CM2/carre
Executable file
Binary file not shown.
52
BUT1/DEV1.1/CM2_2/CM2/carre.c
Normal file
52
BUT1/DEV1.1/CM2_2/CM2/carre.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
#include "lightness.h"
|
||||
|
||||
#define LIGHT 0
|
||||
#define DARK 1
|
||||
#define RED 1
|
||||
#define GREEN 2
|
||||
#define BLUE 4
|
||||
#define LIGHT_RED 217
|
||||
#define DARK_RED 124
|
||||
#define LIGHT_GREEN 157
|
||||
#define DARK_GREEN 34
|
||||
#define LIGHT_BLUE 147
|
||||
#define DARK_BLUE 19
|
||||
|
||||
|
||||
|
||||
int hue(void) {
|
||||
int choice = rand()%3;
|
||||
if (choice == 0) {
|
||||
return RED;
|
||||
} else if (choice == 1) {
|
||||
return GREEN;
|
||||
} else /* if (choice == 2) */ {
|
||||
return BLUE;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int l, c, v;
|
||||
|
||||
srand(time(NULL));
|
||||
l = lightness();
|
||||
c = hue();
|
||||
|
||||
if (c == RED) {
|
||||
v = (l == LIGHT) ? LIGHT_RED : DARK_RED;
|
||||
} else if (c == GREEN) {
|
||||
v = (l == LIGHT) ? LIGHT_GREEN : DARK_GREEN;
|
||||
} else /* if (c == BLUE) */ {
|
||||
v = (l == LIGHT) ? LIGHT_BLUE : DARK_BLUE;
|
||||
}
|
||||
|
||||
printf("┏━━━━┓\n");
|
||||
printf("┃\33[48;5;%dm \33[m┃\n", v);
|
||||
printf("┃\33[48;5;%dm \33[m┃\n", v);
|
||||
printf("┗━━━━┛\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
13
BUT1/DEV1.1/CM2_2/CM2/exo1.c
Normal file
13
BUT1/DEV1.1/CM2_2/CM2/exo1.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char* argv[]){ /* ou "char**"" */
|
||||
long numerateur = strtol(argv[1],NULL,10);
|
||||
long denominateur = strtol(argv[2],NULL,10);
|
||||
ldiv_t calcul = ldiv(numerateur,denominateur);
|
||||
|
||||
printf("quotient : %d\n",calcul.quot);
|
||||
printf("reste : %d\n",calcul.rem);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
39
BUT1/DEV1.1/CM2_2/CM2/exo3.c
Normal file
39
BUT1/DEV1.1/CM2_2/CM2/exo3.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int* suite(int entier){
|
||||
int i = 0, result = entier, nombre_operation;
|
||||
int* tab;
|
||||
|
||||
for (nombre_operation = 0; (result % 2) != 0; i++){
|
||||
result = result / 2;
|
||||
}
|
||||
|
||||
tab = (int*) malloc(nombre_operation * sizeof(int));
|
||||
tab[0] = entier;
|
||||
|
||||
for (i = 1; (entier % 2) != 0; i++){
|
||||
entier = entier / 2;
|
||||
tab[i] = entier;
|
||||
printf("%d", tab[i]);
|
||||
}
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
int i;
|
||||
int* tab1 = suite(5);
|
||||
int* tab2 = suite(6);
|
||||
int* tab3 = suite(7);
|
||||
|
||||
for(i=0;i<10;i++){
|
||||
printf("%d\n",tab1[i]);
|
||||
}
|
||||
|
||||
free(tab1);
|
||||
free(tab2);
|
||||
free(tab3);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
27
BUT1/DEV1.1/CM2_2/CM2/exo4.c
Normal file
27
BUT1/DEV1.1/CM2_2/CM2/exo4.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
FILE* fichier = NULL;
|
||||
int taille_fichier = 0,entier = 0, resultat_fscanf = 0;
|
||||
|
||||
fichier = fopen("reitne","r");
|
||||
if(fichier == NULL){
|
||||
fputs("reitne inaccessible !\n",stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fseek(fichier,0L,SEEK_END);
|
||||
taille_fichier = ftell(fichier);
|
||||
|
||||
while(1){
|
||||
resultat_fscanf = fscanf(fichier,"%d",&entier);
|
||||
if(resultat_fscanf != 1){
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("%d",entier);
|
||||
|
||||
fclose(fichier);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
12
BUT1/DEV1.1/CM2_2/CM2/lightness.c
Normal file
12
BUT1/DEV1.1/CM2_2/CM2/lightness.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include<time.h>
|
||||
#include "lightness.h"
|
||||
|
||||
int lightness(void) {
|
||||
if (time(NULL)%2) {
|
||||
return LIGHT;
|
||||
} else {
|
||||
return DARK;
|
||||
}
|
||||
}
|
9
BUT1/DEV1.1/CM2_2/CM2/lightness.h
Normal file
9
BUT1/DEV1.1/CM2_2/CM2/lightness.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef LIGHTNESS_H
|
||||
#define LIGHTNESS_H
|
||||
|
||||
#define LIGHT 0
|
||||
#define DARK 1
|
||||
|
||||
int lightness(void);
|
||||
|
||||
#endif /* LIGHTNESS_H */
|
7
BUT1/DEV1.1/CM2_2/EntrainementDS2/.vscode/settings.json
vendored
Normal file
7
BUT1/DEV1.1/CM2_2/EntrainementDS2/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"repetition.h": "c",
|
||||
"mktime.C": "cpp"
|
||||
},
|
||||
"editor.inlineSuggest.showToolbar": "onHover"
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
long int nanoseconde;
|
||||
int seconde;
|
||||
|
||||
printf("Entrez le nombre de nanosecondes : ");
|
||||
scanf("%ld", &nanoseconde);
|
||||
|
||||
seconde = nanoseconde / 1000000000;
|
||||
|
||||
printf("Le nombre de secondes est : %d \n", seconde);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int seconde;
|
||||
long int nanoseconde;
|
||||
|
||||
printf("Entrez le nombre de secondes : ");
|
||||
scanf("%d",&seconde);
|
||||
|
||||
nanoseconde = seconde * 1000000000;
|
||||
|
||||
printf("Le nombre de nanosecondes est : %ld \n", nanoseconde);
|
||||
|
||||
return 0;
|
||||
}
|
18
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/.vscode/c_cpp_properties.json
vendored
Normal file
18
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
24
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/.vscode/launch.json
vendored
Normal file
24
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/export/home/an23/stiti/Desktop/EntrainementDS2/SUJET1 /EXO 1",
|
||||
"program": "/export/home/an23/stiti/Desktop/EntrainementDS2/SUJET1 /EXO 1/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
37
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/.vscode/settings.json
vendored
Normal file
37
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wconversion",
|
||||
"-Wnull-dereference",
|
||||
"-Wsign-conversion"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false
|
||||
}
|
14
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/Makefile
Normal file
14
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
# BUT PRINCIPAL
|
||||
repetition_ou_pas : main.o repetition.o
|
||||
gcc -ansi -pedantic -o repetition_ou_pas repetition.o main.o
|
||||
|
||||
repetition.o : repetition.c
|
||||
gcc -ansi -pedantic -c repetition.c
|
||||
|
||||
main.o : main.c repetition.h
|
||||
gcc -ansi -pedantic -c main.c
|
||||
|
||||
clean :
|
||||
rm -f main.o repetition.o
|
||||
|
||||
.PHONY : clean
|
25
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/main.c
Normal file
25
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/main.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "../EXO 1/repetition.h"
|
||||
|
||||
|
||||
int main(int argc,char* argv[]){ /* Ou "char** argv" */
|
||||
int i;
|
||||
long* tab;
|
||||
tab = (long*) malloc(argc*sizeof(long));
|
||||
/* Création d'un tableau de argc - 1 élément (Autrement dit, création d'un tableau du nombre d'éléments donner en argument au programme sans compter le a.out)*/
|
||||
for(i=1;i<argc;i++){
|
||||
tab[i-1] = strtol(argv[i],NULL,10);
|
||||
}
|
||||
|
||||
if(repetition(tab,argc-1)==0){
|
||||
printf("les valeurs sont différentes");
|
||||
}
|
||||
if(repetition(tab,argc-1)==1){
|
||||
printf("les valeurs sont identiques");
|
||||
}
|
||||
free(tab);
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
13
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/repetition.c
Normal file
13
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/repetition.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int repetition(long tab[], int taille){
|
||||
int i;
|
||||
for(i=0;i<taille-1;i++){
|
||||
if(tab[i]!=tab[i+1]){
|
||||
return 0; /*False*/
|
||||
}
|
||||
}
|
||||
return 1; /*True*/
|
||||
}
|
||||
|
@@ -0,0 +1,6 @@
|
||||
#ifndef REPETITION_H
|
||||
#define REPETITION_H
|
||||
|
||||
int repetition(long tab[], int taille);
|
||||
|
||||
#endif /* REPETITION_H */
|
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/repetition_ou_pas
Executable file
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO 1/repetition_ou_pas
Executable file
Binary file not shown.
26
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO2/exo2.c
Normal file
26
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO2/exo2.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
FILE* fichier;
|
||||
char couleur;
|
||||
int i,a=5;
|
||||
fichier = fopen("image","r");
|
||||
if(fichier==NULL){
|
||||
fputs("Erreur d'ouverture du fichier",stderr);
|
||||
return EXIT_FAILURE;
|
||||
}else{
|
||||
while(feof(fichier)!=1){
|
||||
a = fread(&couleur,1,1,fichier);
|
||||
if(couleur == 0){
|
||||
printf("\n");
|
||||
}else{
|
||||
printf("\33[48;5;%hhum \33[m",couleur);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fclose(fichier);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO2/image
Normal file
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO2/image
Normal file
Binary file not shown.
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO2/image(2)
Normal file
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO2/image(2)
Normal file
Binary file not shown.
23
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO3/exo3.c
Normal file
23
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET1 /EXO3/exo3.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void){
|
||||
int i;
|
||||
|
||||
struct timeval tv1;
|
||||
struct timeval tv2;
|
||||
|
||||
gettimeofday(&tv1,NULL);
|
||||
|
||||
for(i=0;i<1000000;i++){
|
||||
sqrt(2);
|
||||
}
|
||||
|
||||
gettimeofday(&tv2,NULL);
|
||||
|
||||
printf("%dμs",tv2.tv_usec-tv1.tv_usec);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
34
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/Makefile
Normal file
34
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/Makefile
Normal 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 ###
|
15
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/main.c
Normal file
15
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/main.c
Normal 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));
|
||||
}
|
13
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/recherche.c
Normal file
13
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/recherche.c
Normal 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;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
#ifndef RECHERCHE_H
|
||||
#define RECHERCHE_h
|
||||
|
||||
int recherche(double tab[], int taille);
|
||||
|
||||
#endif /* RECHERCHE_H */
|
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/valeurs_nulles
Executable file
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/valeurs_nulles
Executable file
Binary file not shown.
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/valeurs_nulles_ou_pas
Executable file
BIN
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO1/valeurs_nulles_ou_pas
Executable file
Binary file not shown.
41
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO2/exo2.c
Normal file
41
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO2/exo2.c
Normal 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;
|
||||
}
|
5
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO2/titi.c
Normal file
5
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO2/titi.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void){
|
||||
|
||||
}
|
5
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO2/toto.c
Normal file
5
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO2/toto.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void){
|
||||
int a;
|
||||
}
|
21
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO3/exo3.c
Normal file
21
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET2/EXO3/exo3.c
Normal 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);
|
||||
}
|
49
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/EXO MKTIME/mktime.c
Normal file
49
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/EXO MKTIME/mktime.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <date au format dd/mm/aa>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct tm date;
|
||||
time_t timestamp;
|
||||
|
||||
/* Analyse de la date fournie en argument*/
|
||||
if (sscanf(argv[1], "%d/%d/%d", &date.tm_mday, &date.tm_mon, &date.tm_year) != 3) {
|
||||
fprintf(stderr, "Format de date invalide. Utilisez le format dd/mm/aa.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*La fonction mktime attend une année en nombre d'années depuis 1900*/
|
||||
date.tm_year += 100;
|
||||
/*La fonction mktime attend le mois en nombre de mois depuis janvier*/
|
||||
date.tm_mon--;
|
||||
|
||||
/*Initialisation des autres champs de la structure tm*/
|
||||
date.tm_hour = 0;
|
||||
date.tm_min = 0;
|
||||
date.tm_sec = 0;
|
||||
date.tm_wday = 0;
|
||||
date.tm_yday = 0;
|
||||
date.tm_isdst = -1; /*Indéterminé*/
|
||||
|
||||
/*Conversion de la structure tm en timestamp*/
|
||||
timestamp = mktime(&date);
|
||||
|
||||
if (timestamp == -1) {
|
||||
fprintf(stderr, "Erreur lors de la conversion de la date en timestamp.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*Conversion du timestamp en structure tm pour obtenir le jour de la semaine*/
|
||||
localtime_r(×tamp, &date);
|
||||
|
||||
/*Affichage du jour de la semaine*/
|
||||
const char *jours[] = {"dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"};
|
||||
printf("C'est un %s.\n", jours[date.tm_wday]);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
25
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/conversion.c
Normal file
25
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/conversion.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
fputs("Usage: ./a.out <valeur> <unité>\n",stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
double valeur = atof(argv[1]);
|
||||
char unite = argv[2][0];
|
||||
|
||||
if (unite == 'c' || unite == 'C') {
|
||||
double pouces = valeur / 2.54;
|
||||
printf("%.2fin\n", pouces);
|
||||
} else if (unite == 'i' || unite == 'I') {
|
||||
double centimetres = valeur * 2.54;
|
||||
printf("%.2fcm\n", centimetres);
|
||||
} else {
|
||||
printf("Unité invalide. Utilisez 'cm' ou 'in'.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
36
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/de.c
Normal file
36
BUT1/DEV1.1/CM2_2/EntrainementDS2/SUJET3/de.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
int resultat_lancer;
|
||||
unsigned char valeur_aleatoire;
|
||||
size_t octet_lu;
|
||||
/* On ouvre le fichier /dev/random */
|
||||
FILE* fichier_random = fopen("/dev/random", "r");
|
||||
|
||||
/* On vérifie qu'il s'ouvre bien*/
|
||||
if (fichier_random == NULL) {
|
||||
fputs("Erreur lors de l'ouverture de /dev/random", stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* On lit un octet depuis /dev/random */
|
||||
octet_lu = fread(&valeur_aleatoire, sizeof(valeur_aleatoire), 1, fichier_random);
|
||||
/*On vérifie l'octet lu */
|
||||
if (octet_lu != 1) {
|
||||
fputs("Erreur lors de la lecture depuis /dev/random", stderr);
|
||||
fclose(fichier_random);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* On ferme le fichier /dev/random */
|
||||
fclose(fichier_random);
|
||||
|
||||
/* On calcule le résultat du dé (entre 1 et 6) */
|
||||
resultat_lancer = (valeur_aleatoire % 6) + 1;
|
||||
|
||||
/* On affiche le résultat */
|
||||
printf("%d\n", resultat_lancer);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
BUT1/DEV1.1/CM2_2/stiti_CM2.tar.gz
Normal file
BIN
BUT1/DEV1.1/CM2_2/stiti_CM2.tar.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user