Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/wait.h>
- #include <fcntl.h>
- //La funzione è stata riscritta in maniera più ordinata
- int consonante(char c){
- int i;
- char consonanti[] = "BbCcDdFfGgHhLlMmNnPpQqRrSsTtVvZz";
- for(i=0; i<33; i++){
- if(c==consonanti[i]){
- return 1;
- }
- }
- return 0;
- }
- int main(){
- int pid;
- pid=fork();
- if(pid<0){
- fprintf(stderr, "Errore nella creazione del nuovo processo");
- exit(1);
- }
- if(pid==0){
- //hai sbagliato il segnale
- signal(SIGINT, SIG_IGN);
- int fdr, fdw;
- int c=0;
- char control = ' ';
- fdr = open("./PIPPO", O_RDONLY);
- if(fdr<0){
- printf("Errore nell'apertura del file PIPPO / file PIPPO insesistente");
- exit(1);
- }
- //correzione o_flag
- fdw = open("./TOPOLINO.txt", O_CREAT | O_EXCL | O_WRONLY , 0660);
- if(fdw<0){
- printf("Errore nell'apertura del file TOPOLINO");
- exit(1);
- }
- while(read(fdr,&control,1)){
- if(consonante(control)){
- write(fdw, &control, 1);
- c++;
- }
- }
- }else if(pid>0){
- int status = 0;
- printf("il pid del processo figlio: %d\n", waitpid(pid, &status, 0));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement