#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define Max 40
typedef struct data
{
int coeficient;
int exponent;
struct data *next;
} Data;
Data *head1, *head2, *ptr, *ptrD;
void init (Data *);
void get_data (char *, FILE *);
void Add ();
void Multiply ();
void Subtract ();
void swap(Data *, Data*);
int main()
{
FILE *fin;
char str[10], c, oper;
int i,token = 1;
if ((fin = fopen ("poly.in", "r")) == NULL)
{
fprintf (stderr, "Usage: cannot open the istream file\n");
exit (EXIT_FAILURE);
}
head1 = (Data *)malloc (sizeof (Data));
head2 = (Data *)malloc (sizeof (Data));
init (head1);
init (head2);
ptrD = head1;
while ((c = fgetc (fin)) == ' ' || c == '\t');
ungetc (c, fin);
while ((c = fgetc (fin)) != '\n' || feof (fin))
{
ungetc (c, fin);
get_data (str, fin);
ptr = (Data *)malloc (sizeof (Data));
init (ptr);
for (i = 0; str[i] != 'x' && str[i] != '\0'; i++)
{
if (str[i] == '+')
break;
else if (str[i] == '-')
token = -1;
else if (isdigit (str[i]))
ptr->coeficient = ptr->coeficient * 10 + str[i ]- '0';
}
ptr->coeficient *= token;
if (str[i ]== 'x')
{
if (ptr->coeficient == 0)
ptr->coeficient = token;
if (str[i+1] == '\0')
ptr->exponent = 1;
else
for (++i; str[i] != '\0'; i++)
ptr->exponent = ptr->exponent * 10 + str[i] - '0';