Hi,
I'm currently trying to write a code using pipes that counts the multiples of 5 that are between numbers 1-10000. The code i've written so far gives me some pretty weird outputs. I think my problem is the count function in my for loop Could someone help me with this? Thanks.
Code:#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> int main() { int fd[2]; int nbytes; pid_t childpid; int array[10001]; int a; int count; int m; pipe(fd); if((childpid = fork()) == -1) { perror("fork"); exit(1); } if(childpid == 0) { //Child process //close(fd[1]); //Reading arrays //nbytes =read(fd[0], } else { //Parent process //close(fd[0]); } for ( m = 0; m < 10001; m++) { count=0; a=1; while(a<=m) { if((m%5) == 0) count++; a++; array[0]++; } //if( count == 2000) { printf("%d\n",array[0]); //} } //array[m]=m; //Write arrays //write(fd[1], return 0; }



LinkBack URL
About LinkBacks



