From 10a7114e2225c4af0a15123254043a5ef709c7f1 Mon Sep 17 00:00:00 2001 From: lefevres Date: Sat, 2 Oct 2021 11:22:18 +0200 Subject: [PATCH] Add 'ASR3.1/TP02 Fichier/copy.c' --- ASR3.1/TP02 Fichier/copy.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ASR3.1/TP02 Fichier/copy.c diff --git a/ASR3.1/TP02 Fichier/copy.c b/ASR3.1/TP02 Fichier/copy.c new file mode 100644 index 0000000..d65a6dc --- /dev/null +++ b/ASR3.1/TP02 Fichier/copy.c @@ -0,0 +1,33 @@ +#include +#include + +int main(int argc, char *argv[]) { + + FILE *fileIn, *fileOut; + int val; + char ch; + + if (argc!=3) { + printf("Il me faut deux noms de fichiers\n"); + return EXIT_FAILURE; + } + if ((fileIn= fopen(argv[1], "r")) == NULL) { + printf("Je ne peux pas ouvrir %s \n", argv[1]); + return EXIT_FAILURE; + } + if ((fileOut= fopen(argv[2], "w")) == NULL) { + printf("Je ne peux pas ouvrir %s\n", argv[2]); + return EXIT_FAILURE; + } + + while ((val=fgetc(fileIn)) !=EOF) { + printf("%d ", val); + fputc(val, fileOut); + ch = val; + printf("%d\n", ch); + } + + fclose(fileIn); + fclose(fileOut); + return EXIT_SUCCESS; +} \ No newline at end of file