$ cp -r ~steve/ex/funptr .
Look at fold.c. The foldl() function at the top of the file is an instance of a fold. It takes an array of integers (and its size), an initial value, and a pointer to a function of two ints that returns an int. It iterates through the array, applying the function to initial and the next element in the list, updating initial each time.
fold.c
foldl()
int
initial
Write a function add such that foldl(num, arr, 0, add) computes the sum of the num integers in arr. Have main print out the result of that.
add
foldl(num, arr, 0, add)
num
arr
main
mult
foldl
min
max
INT_MIN
INT_MAX
Write a function print that you can use with foldl to print out (via printf(3)) each of the elements in the array.
print
printf(3)
When you run your code, you should get something like this.
$ ./fold array: -8 2 5 19 20 -72 sum: -34 product: 2188800 min: -72 max: 20
courses.c
qsort(3)
print_courses()