BUT2/SCR/SCR1.2/TP11/Q3.c
2023-10-23 13:23:36 +02:00

35 lines
708 B
C

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#define STDOUT 1
#define STDERR 2
#define SZBUF 256
int main(int argc, char** argv){
int descripteur;
ssize_t echec;
char buf[SZBUF];
if (argc < 2){
fprintf(stderr, "Usage : %s <file-name>\n",argv[0]);
exit(1);
}
descripteur = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0600);
if (descripteur==-1){
perror("opening file fail !");
exit(2);
}
write(1,"Numb --> ",9);
while (echec = read(0,buf,SZBUF)){
echec = write(descripteur,buf,echec);
if (echec==-1){
perror("writing in file failed!");
exit(3);
}
write(1,"Numb --> ",9);
}
close(descripteur);
exit(0);
}