Update 'ASR3.1/TP02 Fichier/copy2.c'

This commit is contained in:
lefevres 2021-10-04 13:36:54 +02:00
parent af5eae765f
commit 41c2fd6325

View File

@ -1,33 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
#define N 1
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;
int main(int argc, char const *argv[]) {
int fIn, fOut;
char buff [N];
fIn = open (argv[1], O_RDONLY);
assert (fIn >= 0);
fOut = open (argv[2 ], O_WRONLY | O_CREAT, 0600);
assert (fOut >=0);
while (1){
ssize_t nbRead = read (fIn, buff, N);
if (nbRead <=0) {
break;
} else {
write (fOut, buff, N);
}
while ((val=fgetc(fileIn)) !=EOF) {
printf("%d ", val);
fputc(val, fileOut);
ch = val;
printf("%d\n", ch);
}
fclose(fileIn);
fclose(fileOut);
return EXIT_SUCCESS;
close (fIn);
close (fOut);
}