daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Feb 19th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/types.h>
  2. #include <sys/wait.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <ctype.h>
  6. #include <stdlib.h>
  7.  
  8. int main (void)
  9. {
  10.   pid_t retour ;
  11.   int tube[2], lettre = 0, chiffre = 0 ;
  12.   char k ;
  13.   if (pipe (tube) == -1) { perror ("creation pipe impossible\n") ; exit (1) ; }
  14.   switch (retour = fork ()) {
  15.     case -1 : perror ("Creation impossible") ; exit(1) ;
  16.  
  17.     case 0  :
  18.       printf ("processus fils\n") ;
  19.       close (tube[1]) ;
  20.       do{
  21.           read (tube[0], &k, 1);
  22.        if (isdigit (k)) chiffre++ ;
  23.         else lettre++ ;
  24.       }while (k!='.');
  25.       printf ("%d chiffres recus\n", chiffre) ;
  26.       printf ("%d lettres recues\n", lettre) ;
  27.      close (tube[0]) ;
  28.       exit (0) ;
  29.  
  30.     default :
  31.       printf ("pere: a cree processus %d\n", retour) ;
  32.       close (tube[0]) ;
  33.       while (read (0, &k, 1) >0){
  34.         write (tube[1], &k, 1) ;
  35.       }
  36.       close (tube[1]) ;
  37.       wait (0) ;
  38.       printf ("pere: a recu terminaison fils\n") ;
  39.   }
  40.   return 1 ;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top