/* * CS460: Operating Systems * Jim Plank * stuff.c -- producer/consumer read/write/print routines */ #include struct inputstruct { char s[2000]; }; struct outputstruct { int sum; }; struct inputstruct *read_input() { struct inputstruct *is; is = (struct inputstruct *) malloc(sizeof(struct inputstruct)); if (gets(is->s) == NULL) { free(is); return NULL; } else { return is; } } struct outputstruct *process_input(is) struct inputstruct *is; { struct outputstruct *os; int i1, i2, i3, i4; i1 = 0; i2 = 0; i3 = 0; i4 = 0; os = (struct outputstruct *) malloc(sizeof(struct outputstruct)); sscanf(is->s, "%d %d %d %d", &i1, &i2, &i3, &i4); os->sum = i1+i2+i3+i4; free(is); return os; } print_output(os) struct outputstruct *os; { printf("Sum: %d\n", os->sum); free(os); }