I am going to multiply two polynomial that user must enter.
in the first step (getting info from user) I got this error:
Unhandled exception at 0x00a315cb in linked polinomials.exe:
0xC0000005: Access violation writing location 0x00000000.
I got this error after that I want to enter an other element of polynomial.
struct polynomial{
float coef ;
int exp ;
polynomial *next ;
} *first, *second ,*result;
first = new(polynomial);
//init first
first ->coef = 0;
first->exp = 0 ;
first->next = 0;
while(ch != 'n')
{
cin >> temp_c ;
cin >> temp_e ;
first->coef = temp_c;
first->exp = temp_e;
cout << "Do you want to enter another ? (y or n) :" << endl;
ch = getch();
first = first->next;
}
In the first iteration:
you assign
firsttoNULL, because that’s whatfirst->nextis initially. You need to allocate space for it before the assignment.Also, are you sure you want to lose the pointer to the first node?