Exercice 1:

read_file.c fait la même chose que cat.


#define BUTS7 256
#define LEN 128

int main(int argc,char*argv[]
{
 int n
 if(argc<2)
 {
  n=snprintf(str,LEN,"Usage: %s <FILE_NAME>\n",argv[0]);
  write(2,str,n);
  exit(1);
 }
}
//alternative
if(argc<2)
{
 write(2,"Usages: ",7);
 write(2,argv[0],strlen(argv[0]));
 write(2," <FILE_NAME>\n",13);
 exit(1);
}
  

fd=open(argv[1],O_RDONLY);
if(fd ==-1)
{
 perror("Openning file fails"); //perror affiche mon message puis le message standard associé a l'erreur qui vient de se produire
 exit(2);
}
while(n=read(fd,buf,BUFS7))
{
 if(n==1)
 {
  perror("Read in file fails");
  exit(3);
 }
 while(m==write(1,buf,n));
 if(m==-1)
 {
  perror("write to stdait fails");
  exit(4);
 }
 close(fd);
 exit(0);
}

--------------------------------------------------------------------------------------------------------------
Exercice 2:

Copy.c fait la même chose que cp

#define BUFS7 256
#define LEN 128

int main(int argc,char*argv[])
{
 int fdr,fdw,m,n;char buf[BUFS7];char str[LEN];
 if(argc<3)
 {
  n =snprintf(str,LEN,"Usage %s <SRC_FILE><DEST_FILE>\n",argv[0]);
  write(2,str,n);
  exit(1);
 }
 fdr=open (argv[1],O_RDONLY];
 if(fdr==-1)
 {
  perror("Openning SRC_FILES fails");
  exit(2);
 }
 fdw=open(argv[2],O_WRONLY|O_CREAT|O_TRUNC,0600);
 if(fdw==-1)
 {
  perror("Openning DEST_FILE fails");
  exit(3);
 }
 
--------------------------------------------------------------------------------------------------------------

Exercice 4 :

fd = open(argv[1]; ...)
write(1,"Numb --> ",9);
while (n =read (0,s,BUFS7))
{
 if (n == -1)
 {
  
