Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <signal.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/wait.h>
  8. #include <fcntl.h>
  9.  
  10. //La funzione è stata riscritta in maniera più ordinata
  11. int consonante(char c){
  12. int i;
  13. char consonanti[] = "BbCcDdFfGgHhLlMmNnPpQqRrSsTtVvZz";
  14. for(i=0; i<33; i++){
  15. if(c==consonanti[i]){
  16. return 1;
  17. }
  18. }
  19. return 0;
  20. }
  21.  
  22. int main(){
  23. int pid;
  24. pid=fork();
  25. if(pid<0){
  26. fprintf(stderr, "Errore nella creazione del nuovo processo");
  27. exit(1);
  28. }
  29. if(pid==0){
  30. //hai sbagliato il segnale
  31. signal(SIGINT, SIG_IGN);
  32. int fdr, fdw;
  33. int c=0;
  34. char control = ' ';
  35. fdr = open("./PIPPO", O_RDONLY);
  36. if(fdr<0){
  37. printf("Errore nell'apertura del file PIPPO / file PIPPO insesistente");
  38. exit(1);
  39. }
  40. //correzione o_flag
  41. fdw = open("./TOPOLINO.txt", O_CREAT | O_EXCL | O_WRONLY , 0660);
  42. if(fdw<0){
  43. printf("Errore nell'apertura del file TOPOLINO");
  44. exit(1);
  45. }
  46. while(read(fdr,&control,1)){
  47.  
  48. if(consonante(control)){
  49.  
  50. write(fdw, &control, 1);
  51. c++;
  52. }
  53. }
  54.  
  55. }else if(pid>0){
  56. int status = 0;
  57. printf("il pid del processo figlio: %d\n", waitpid(pid, &status, 0));
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement