Skip to content

Commit

Permalink
Finishing touches, formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeada committed Oct 2, 2014
1 parent c646a94 commit cd5e9b7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mm.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/wait.h>

#define debug 0

Expand All @@ -19,7 +19,7 @@ int mean (int *v, int length) {
int i;
int sum = 0;
for(i = 0; i < length; i++) {
sum = sum + v[i];
sum = sum + v[i];
}
return sum/length;
}
Expand Down Expand Up @@ -64,14 +64,15 @@ int main(int argc, char *argv[]) {
if (rc == -1) {
// could not fork another process
fprintf(stdout, "Fork failed.\n");
exit(-1);
exit(-1);
} else if (rc == 0) { // child runs median:
int med = median(pt, length);
fprintf(stdout, "Median = %d ", med);
fprintf(stdout, "Median = %d \n", med);
} else if (rc > 0) { // parent runs mean:
wait(NULL); // waits until child has finished
int avg = mean(pt, length);
fprintf(stdout, "Mean = %d ", avg);
int avg = mean(pt, length);
fprintf(stdout, "Mean = %d ", avg);

}

fprintf(stdout, "\n%s: FIN. \n", argv[0]);
Expand Down

0 comments on commit cd5e9b7

Please sign in to comment.