download | new post | emilian_ex1 on April Mon 13th 1:33 PM - Never Expires
- #include<stdio.h>
- #include<unistd.h>
- #include<stdlib.h>
- int main(int argc,char* argv[])
- {
- int n,nr,aux,j,i,pid;
- FILE *f1,*f2,*f3;
- f1 = fopen("f1i.txt","w");
- f2 = fopen("f2i.txt","w");
- f3 = fopen("f3i.txt","w");
- if(f1==NULL || f2==NULL || f3==NULL)
- {
- exit(1);
- }
- aux=1;
- do
- {
- scanf("%d",&n);
- if(n<0 || n>30000)
- }while(n<0||n>30000);
- for(i=0;i<n;i++)
- {
- scanf("%d",&nr);
- if(aux==1)
- fprintf(f1,"%d ",nr);
- if(aux==2)
- fprintf(f2,"%d ",nr);
- if(aux==3)
- fprintf(f3,"%d ",nr);
- aux++;
- if(aux==4)
- aux = 1;
- }
- fclose(f1);
- fclose(f2);
- fclose(f3);
- //am terminat de scris numerele in fisiere NOT
- for(i=1;i<=3;i++)
- {
- if((pid=fork())==-1)
- {
- exit(2);
- }
- if(0 == pid)
- {
- //fiu
- FILE *f4;
- if(i==1)
- { /*
- int s1=0,n1;
- f1 = fopen("f1i.txt","r");
- f4 = fopen("f1o.txt","w");
- while(!feof(f1))
- {
- fscanf(f1,"%d ",&n1);
- s1+=n1;
- }
- fprintf(f4,"%d",s1);
- fclose(f1);
- fclose(f4);*/
- execl("./worker","worker","f1i.txt","f1o.txt",NULL);
- }
- else if(i==2)
- {/*
- int s2=0,n2;
- f2 = fopen("f2i.txt","r");
- f4 = fopen("f2o.txt","w");
- while(!feof(f2))
- {
- fscanf(f2,"%d ",&n2);
- //printf("!!%d!!",n2);
- s2+=n2;
- }
- fprintf(f4,"%d",s2);
- fclose(f2);
- fclose(f4);*/
- execl("./worker","worker","f2i.txt","f2o.txt",NULL);
- }
- else
- {/*
- int s3=0,n3;
- f3 = fopen("f3i.txt","r");
- f4 = fopen("f3o.txt","w");
- while(!feof(f3))
- {
- fscanf(f3,"%d ",&n3);
- s3+=n3;
- //printf("!!%d!!",n3);
- }
- fprintf(f4,"%d",s3);
- fclose(f3);
- fclose(f4);
- */
- execl("./worker","worker","f3i.txt","f3o.txt",NULL);
- }
- }
- }
- for(j=1;j<=3;j++)
- wait(NULL);
- return 0;
- }
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.