update
This commit is contained in:
13
DEV.1.1/CM3/blague.c
Normal file
13
DEV.1.1/CM3/blague.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<time.h>
|
||||
|
||||
int main(void) {
|
||||
srand(time(NULL));
|
||||
if (rand()%2) {
|
||||
printf("Ϳоie !\n");
|
||||
} else {
|
||||
printf("Désespoir !\n");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
BIN
DEV.1.1/CM3/ex1
Executable file
BIN
DEV.1.1/CM3/ex1
Executable file
Binary file not shown.
40
DEV.1.1/CM3/ex1.c
Normal file
40
DEV.1.1/CM3/ex1.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int bilan(int tab[], int taille){
|
||||
int i,n = taille, nb_suivant;
|
||||
|
||||
if(n==0){
|
||||
printf("%d\n", taille);
|
||||
return tab[0];
|
||||
}
|
||||
|
||||
nb_suivant = bilan(tab + 1, taille - 1);
|
||||
return (tab[0]>0) ? tab[0] : nb_suivant;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int n;
|
||||
int *tab;
|
||||
|
||||
n = argc - 1;
|
||||
valeurs = (int*)malloc(n * sizeof(int));
|
||||
if (valeurs == NULL) {
|
||||
fprintf(stderr, "Erreur d'allocation mémoire\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
tab[i] = atoi(argv[i + 1]);
|
||||
}
|
||||
|
||||
printf("%d\n", bilan(tab, taille));
|
||||
|
||||
free(tab);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
76
DEV.1.1/CM3/ex2.c
Normal file
76
DEV.1.1/CM3/ex2.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TEMP_FILE_NAME "tempfile.tmp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *file, *tempFile;
|
||||
char buffer[1024];
|
||||
size_t bytesRead;
|
||||
|
||||
file = fopen(argv[0], "r+");
|
||||
if (file == NULL) {
|
||||
perror("Erreur d'ouverture du fichier");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Création d'un fichier temporaire */
|
||||
tempFile = tmpfile();
|
||||
if (tempFile == NULL) {
|
||||
perror("Erreur de création du fichier temporaire");
|
||||
fclose(file);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
size_t read;
|
||||
/* réecriture du texte dans le fichier temporaire en remplaçant les points d'interrogation grecs par des points-virgules*/
|
||||
while(1){
|
||||
read = fread(buffer, sizeof(*buffer),file)
|
||||
if("0xCD" || "0xBE")
|
||||
if () {
|
||||
perror("Erreur d'écriture dans le fichier temporaire");
|
||||
fclose(file);
|
||||
fclose(tempFile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Copier le contenu du fichier original dans le fichier temporaire */
|
||||
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||
if (fwrite(buffer, 1, bytesRead, tempFile) != bytesRead) {
|
||||
perror("Erreur d'écriture dans le fichier temporaire");
|
||||
fclose(file);
|
||||
fclose(tempFile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Retour au début des fichiers */
|
||||
rewind(tempFile);
|
||||
rewind(file);
|
||||
|
||||
/* Copier le contenu du fichier temporaire dans le fichier original */
|
||||
while ((bytesRead = fread(buffer, 1, sizeof(buffer), tempFile)) > 0) {
|
||||
if (fwrite(buffer, 1, bytesRead, file) != bytesRead) {
|
||||
perror("Erreur d'écriture dans le fichier original");
|
||||
fclose(file);
|
||||
fclose(tempFile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tronquer le fichier au cas où il serait plus grand que le contenu écrit */
|
||||
if (fflush(file) != 0 || ftruncate(fileno(file), ftell(file)) != 0) {
|
||||
perror("Erreur lors de la troncation du fichier");
|
||||
fclose(file);
|
||||
fclose(tempFile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Fermeture des fichiers */
|
||||
fclose(file);
|
||||
fclose(tempFile);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user