With a binary read from the file writes garbage in 1 factor, the rest is all fine. Text reading do not know how to organize, here's the code: http://www.cyberforum.ru/c-beginners/thread1865879.html#post9841925

Closed due to the fact that off-topic participants are Vladimir Martyanov , Vlad from Moscow , post_zeew , aleksandr barakin , Harry Dec 2 '16 at 7:48 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Vladimir Martyanov, post_zeew, aleksandr barakin, Harry
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    The minimally reproducible example is needed in the question. - Vladimir Martyanov
  • How to create a minimal, self-sufficient and reproducible example . Anyone in your code sheet is not interesting to understand. - PinkTux
  • 2
    error in 30-33 lines. In a loop in line 30, it starts from n to 0. And the array itself has a size of n elements. Thus, when you first write to the array, write outside. Similarly, in 43 and others. Most likely, instead of i=n you need to write i=n-1 . - KoVadim
  • @KoVadim: We must first decide what n is — the degree of the polynomial or the size of the coefficient array. A polynomial of degree n has an n+1 coefficient. If n is the degree of a polynomial, then vice versa, it is necessary to increase the size of the array to n+1 and mention it everywhere. - AnT

1 answer 1

Nothing "great" is there.

If the degree of a polynomial is n , then the number of coefficients of such a polynomial is n+1 . You are well aware of this, because in the Enter function you enter exactly n+1 coefficients.

However, you allocate memory everywhere only under the n elements of the array and write-read only for n elements. Therefore, in Enter there is a departure beyond the limits of the array and one coefficient is then lost. Throughout the program, such errors are scattered, including in the functions of reading and writing.

You must first decide what n is — the degree of the polynomial or the size of the coefficient array. If n is the degree of a polynomial, then increase the size of the array to n+1 and mention it everywhere. If n is the size of the coefficient array, then it must be remembered that the degree of the polynomial is n-1 .

Either that or that way.