From b00225af7078744907be73cef7c78217cad259db Mon Sep 17 00:00:00 2001 From: Mazen BEN GHORBAL Date: Tue, 10 Dec 2024 15:32:15 +0100 Subject: [PATCH] Supprimer exo3.c --- exo3.c | 90 ---------------------------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 exo3.c diff --git a/exo3.c b/exo3.c deleted file mode 100644 index e22a3c0..0000000 --- a/exo3.c +++ /dev/null @@ -1,90 +0,0 @@ -include -#include - -void deplacerPremierOctet(const char *filename) { - FILE *file; - unsigned char first_byte; - long file_size; - unsigned char *buffer; - - - file = fopen(filename, "r+b"); - if (file == NULL) { - perror("Erreur d'ouverture"); - exit(EXIT_FAILURE); - } - - if (fread(&first_byte, 1, 1, file) != 1) { - perror("Erreur de lecture"); - fclose(file); - exit(EXIT_FAILURE); - } - - fseek(file, 0, SEEK_END); - if (fwrite(&first_byte, 1, 1, file) != 1) { - perror("Erreur d'écriture"); - fclose(file); - exit(EXIT_FAILURE); - } - - file_size = ftell(file); - fclose(file); - - file = fopen(filename, "r+b"); - if (file == NULL) { - perror("Erreur d'ouverture"); - exit(EXIT_FAILURE); - } - - buffer = (unsigned char *)malloc(file_size - 1); - if (buffer == NULL) { - perror("Erreur d'allocation mémoire"); - fclose(file); - exit(EXIT_FAILURE); - } - - fseek(file, 1, SEEK_SET); - if (fread(buffer, 1, file_size - 1, file) != file_size - 1) { - perror("Erreur de lecture"); - free(buffer); - fclose(file); - exit(EXIT_FAILURE); - } - fclose(file); - - file = fopen(filename, "wb"); - if (file == NULL) { - perror("Erreur d'ouverture"); - free(buffer); - exit(EXIT_FAILURE); - } - - if (fwrite(buffer, 1, file_size - 1, file) != file_size - 1) { - perror("Erreur d'écriture"); - free(buffer); - fclose(file); - exit(EXIT_FAILURE); - } - - if (fwrite(&first_byte, 1, 1, file) != 1) { - perror("Erreur d'écriture"); - free(buffer); - fclose(file); - exit(EXIT_FAILURE); - } - - free(buffer); - fclose(file); - - printf("Modification effectuée.\n"); -} - -int main(int argc, char *argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(EXIT_FAILURE); - } - - deplacerPremierOctet(argv[1]); - return 0; -} \ No newline at end of file