It is best to separate program functionality. The code Richard gave you will accept input and process it into an array of five integers. These are the coefficients in your program. The value five could be anything else you want - it corresponds to the degree in your program. You could accept that value as the initial input. Even better would be to make a function to accept all inputs needed for each polynomial.
One step you seem to be missing is the polynomial evaluation. Like the input function I suggested, you could make a function that accepts a polynomial structure and a value of X and generates a result.
If I were you, I would tweak the input function to accept a file pointer so you can read input from a text file. That lets you work much faster than if you have to input numbers every time. It can read the file and process the same set of inputs every time or it can process any file of inputs you want it to, including from stdin which is really just another file pointer.
Here's how that might look :
#define INPUT_SIZE = 127
int GetCoefficients( polynomial * ppoly, int degree, FILE * fin )
{
const char * delimiters = " \t\r\n";
char buffer[ INPUT_SIZE+1 ] = { 0 };
char * intext = buffer;
char * pnext = NULL;
int i = 0;
ppoly->coef = (int *) calloc( degree + 1, sizeof( int ) );
fgets( text, INPUT_SIZE, fin );
for( i = 0; i <= degree; i++ )
{
pnext = strtok( intext, delims );
if( pnext == NULL )
return 0;
ppoly->coef[ i ] = atoi( pnext );
intext = NULL; }
for( i = 0; i <= degree; i++ )
{
printf("coefficient %d is %d\n", i, ppoly->coef[ i ] );
}
return degree + 1;
}
Note the
<=
on the loops. That's because I think you need one more coefficient than the degree of the polynomial to account for the constant factor which is actually the coefficient for x raised to the zero power.
This function takes degree as an input parameter. It can be acquired exactly like how the input is read here.