Skip to content

Commit

Permalink
Parent and Child process of mm.c print results
Browse files Browse the repository at this point in the history
---------------------------------------------
- Fix smuos#5
- Fix smuos#6
- Fixes smuos#7
- Fix minor problem with median()
  • Loading branch information
DylanYoung committed Sep 24, 2014
1 parent 49ae891 commit 6bcafdf
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ double mean(const void *a, int length, int size){
double median(const int *a, int length){
double result;
if (length % 2 == 0)
result = (*((int*) (a + length/2) - 1) + *((int*) (a + length/2)) ) / 2;
result = (double) (*((int*) (a + length/2) - 1) + *((int*) (a + length/2)) ) / 2;
else
result = *((int*) (a + (length+1)/2 - 1));
return result;
Expand Down Expand Up @@ -87,18 +87,22 @@ int main(int argc, char *argv[]) {
exit(-1);
else if (rc == 0){
// Calculate the median
m = median(pt, length);
m = median(pt, length);

// Print the median:
fprintf(stdout, "%s: The median is %f \n", argv[0], m);

exit(0);
}
else{
wait(NULL);
// Calculate the mean
m = mean(pt, length, sizeof(int));
}

// Print the mean:
fprintf(stdout, "%s: The mean is %f \n", argv[0], m); }


// Print the mean?:
fprintf(stdout, "%s: The mean? is %f \n", argv[0], m);

// Print out sorted numbers
fprintf(stdout, "%s: Sorted output is: \n", argv[0]);
for (i=0; i<length; i++) {
Expand Down

0 comments on commit 6bcafdf

Please sign in to comment.