Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///BISOGNA CREARE IL FILE "testfile.txt" ALL'INTERNO DELLA CARTELLA DOVE È PRESENTE IL "main.c"
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main()
- {
- ///Dichiaro il buffer
- char buffer[2];
- char buffer_o[2];
- ///Dichiaro il descrittore
- int fp_i,fp_o,fp_i_2,fp_o_2;
- ///Dichiato i due interi e la var di somma
- int n1,n2,somma;
- ///Apro il descrittore
- fp_i=open("testfile.txt",O_RDONLY , 0700);
- fp_i_2=dup(fp_i);
- fp_o=open("outputfile.txt",O_CREAT | O_WRONLY | O_TRUNC, 0700);
- fp_o_2=dup(fp_o);
- ///Procedura di input
- while((read(fp_i_2,buffer,2))>0)
- {
- if((n1=atoi(buffer))==-1) return 0;
- if((read(fp_i_2,buffer,2))>0)
- {
- n2=atoi(buffer);
- somma=n1+n2;
- sprintf(buffer_o, "%d" , somma);
- if(somma>9)
- {
- write(fp_o_2,buffer_o,sizeof(buffer_o));
- write(STDOUT_FILENO/*OPPURE 1*/,buffer_o,sizeof(buffer_o));
- }
- else
- {
- write(fp_o_2,buffer_o,1);
- write(STDOUT_FILENO/*OPPURE 1*/,buffer_o,1);
- }
- write(fp_o_2," ",1);
- ///lseek(fp_o,1,SEEK_CUR);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement