I want to assign the exponent and coefficient information input from the file to the circular linked list.
file "a.txt" is as follows
8 3
7 2
3 0
However, there are also strange values in the output like this. I wanted to make the list circular, but it doesn't.
coef expon
3 0
7 2
8 3
7887744 0
7900240 0
7864656 0
7869712 0
7900240 0
7864656 0
7869712 0
please, I can't find the solution.
#include <stdio.h>
#include <stdlib.h>
typedef struct polyNode* polyPointer;
typedef struct polyNode{
int coef;
int expon;
polyPointer link;
};
int main() {
polyPointer A, B, C = (polyPointer)malloc(sizeof(polyPointer)) ;
FILE *fa, *fb ;
int a;
fa = fopen("a.txt", "r");
if(fa==NULL){
printf("file open error\n");
return 1;
}
if(fb==NULL){
printf("file open error\n");
return 1;
}
A = create_circle_linked_poly(fa);
printf("coef expon\n");
int i;
for(A; i<10; A=A->link, i++)
printf("%d %d\n", A->coef, A->expon);
return 0;
}
polyPointer create_circle_linked_poly(FILE *a){
polyPointer head = malloc(sizeof(polyPointer));
polyPointer temp = malloc(sizeof(polyPointer));
first = head;
int res;
while(1){
polyPointer p =(polyPointer) malloc(sizeof(polyPointer));
res = fscanf(a, "%d %d", &p->coef, &p->expon);
if(res==EOF)break;
p->link = head;
head = p;
}
return head;
}