scanf() to 1D array

Hi everyone,

I’m having problems reading user inputs from terminal into my array.

the array ‘a’ has a dynamic size. The polynomial which is inputted by the user determines the size of the array.

once compiled and run:

Enter the order number:
3
Enter your constant:
-90
Enter coefficient # 0
8
Enter coefficient # 1
4
Enter coefficient # 2
35
Enter coefficient # 3
54
  0     8.000000
  1     4.000000
  2     0.000000
  3     0.000000

On the debug lines I’m just reporting the array back to user. For some reasons it returns zero for the second half of the array. I can’t figure out what the problem could be. Any help would be greatly appreciated.

PS. ignore eval function.

here is the code I’m working on:

//import required libraries
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// function prptotype
double eval(double a[], double x, int n); //n is max degree
//global variables
int N = 0;//N is the polynomial order
double *a;//array
double	x; // constant
//main function
int main()
{
	printf("%s\n", "Enter the order number:");
	scanf("%d", &N); // user input for the order numbers
	while (N < 1) //input debuger
	{
		printf("%d %s\n%s\n", N,"is NOT a positive and non-zero number", "Enter a positive and non-zero integer:" );
		scanf("%d", &N); // user input for the order numbers
	}
	a = malloc ((N + 1) * sizeof(int));// assigning the array size in respect with user input
	printf("%s\n", "Enter your constant:" );
	scanf("%lf", &x);// user input for "x" constant
	for (int i = 0; i < N + 1; ++i)
	{
		printf("Enter coefficient # %d\n", i);
		scanf ("%lf", &a[i]);
	}
	/* Debug */
	for (int i = 0; i < N + 1; ++i)
	{
		//a[i] = 0;
		printf("%3d%13lf\n", i, a[i]);
	}
}

//eval function
double eval(double a[], double x, int n)
{

}
	a = malloc ((N + 1) * sizeof(double));

aarg:

	a = malloc ((N + 1) * sizeof(double));

That fixed it! Thanks.