Preparatory Work:
The following notes should be useful background for both Lab 4 and Assignment #1 and #2.
One formal definition of polynomial term for ease of programming.
<polynomial> --> {<sign><coeff><exponent>}*
<sign> --> + | -
<coeff> --> FLOAT_NUMBER
<exponent> --> x | x^<degree> | []
<degree> --> INTEGER
use fscanf (fid, "%lf", coeff);
use fscanf (fid, "%d", exponent); or fgetc(fid)
use fgetc (fid) and ungetc(char, fid) to examine characters.
Probably best to copy input stream into an array, removing blanks as you go. Build a pointer to the array and then read from the array just like from a file. Ultimately, being able to view files as a data stream in memory is a big asset in C programs.
As a mathematical note. The polynomial +ax^2 +bx^1 +c
can be written:
c +x(b +x(a))
Polynomials that are rewritten in this form can be evaluated without
the need of the pow() function.
Look at
pointers-1.c
and its associated output
pointers-1.log,
and also
pointers-2.c
and its associated output
pointers-2.log.