I'm still learning about pointers and using malloc, so please bare with me.

I was wondering if it is possible to allocate memory for a pointer in a main function, send that pointer to another function, and then reallocate memory for that same pointer within the secondary function. I assume that this would make no difference to reallocating memory in the main function, correct?

I'm having trouble reallocating memory for a few pointers that I am sending to a secondary function. I am basically collecting user input in the form of arrays (pointers, actually) and then planning to use these pointers to do some calculations in other functions. The problem is that the values are not storing correctly. I get no compiler error, but when i get to the memory reallocation line in the program, I get a segmentation fault and my compiler goes crazy. Obviously, I'm not using malloc and/or realloc correctly, even though I thought I had the right format, based on looking at other code snippets and what not.

Here's my code...sorry for the complex variables, this project I'm working on is a MatLab simulation program conversion.

main function:
Code:
#include<stdio.h>
#include<stdlib.h>
#include"untitledproto.h"

#include"untitled2.c"


int main()
{

int M, i, j, PAS_type, cluster_number;
double *d_norm, *delta_phi_deg, *amplitude_cluster, *phi_deg, *AS_deg;


d_norm = malloc(sizeof(d_norm));
delta_phi_deg = malloc(sizeof(delta_phi_deg));
amplitude_cluster = malloc(sizeof(amplitude_cluster));
phi_deg = malloc(sizeof(phi_deg));
AS_deg = malloc(sizeof(AS_deg));


if (d_norm==NULL)    /*checking for null pointers*/
printf("OUT OF MEMORY!");

if (delta_phi_deg==NULL)
printf("OUT OF MEMORY!");

if (amplitude_cluster==NULL)
printf("OUT OF MEMORY!");

if (phi_deg==NULL)
printf("OUT OF MEMORY!");

if (AS_deg==NULL)
printf("OUT OF MEMORY!");


---------------------------------------------------------------------------------
int data;

data=dialog(d_norm, delta_phi_deg, amplitude_cluster, phi_deg, AS_deg);

cluster_number = (data&#37;100)%10;
M=((data-cluster_number)%100)/10;
PAS_type=(data-(M+cluster_number))/100;



return 0;
}

secondary function...supposed to gather user input and store them as arrays (basically).
Returns one value that is basically a mathematical combination of the array sizes and another variable. This value is then split back apart into 3 separate variable in the main function. (I needed a multiple return).
Code:
#include<stdio.h>
#include<stdlib.h>


double dialog(double *d_norm, double *delta_phi_deg, double *amplitude_cluster, double *phi_deg, double *AS_deg)
{
	
	double spacing=0;
	int M=0, PAS_type=0, cluster_number=0; 
	int i,j;

	while(M<=1)
	{
	
		printf("\nNumber of elements?\t");
		scanf("%d", &M);
	}

	
	d_norm=realloc(d_norm, M*sizeof(d_norm));


	if(M>1)
	{
	
		while(spacing<=0)
		{

			printf("\nNormalized spacing between elements (in wavelengths)?\t");
			scanf("%lf", &spacing);

	

			/*---------Computes Linearly Spaced Vector-------*/
			

			for(i=0; i<M; i++)
			{
				d_norm[i] = (i)*spacing;
			}
			

	
			while(cluster_number<1)
			{

				printf("\nNumber of impinging clusters of waves?\t");
				scanf("%d", &cluster_number);
		
			}

			delta_phi_deg = realloc(delta_phi_deg, cluster_number*sizeof(delta_phi_deg));
				amplitude_cluster = realloc(amplitude_cluster, cluster_number*sizeof(cluster_number));
				phi_deg = realloc(phi_deg, cluster_number*sizeof(phi_deg));
				AS_deg = realloc(AS_deg, cluster_number*sizeof(AS_deg));

			/*----------------^^^ Crashes here ^^^--------------------*/
			PAS_type=0;
	
			while(PAS_type<1 || PAS_type>3)
			{
	
			printf("\nPAS type (1 = Uniform, 2 = Gaussian, 3 = Laplacian)?\t");
			scanf("%d", &PAS_type);

			}

			if(cluster_number==1)
			{
				if(PAS_type!=1)
				{
					delta_phi_deg[0]=-1;
					while(delta_phi_deg[0]<=0)
					{
						printf("\nHalf Domain Definition (in degrees)?\t");
						scanf("%lf", &delta_phi_deg[0]);
				
					}
				}
				else
				{
					delta_phi_deg[0]= 90;
				}

				amplitude_cluster[0]=1;

				printf("\nMean Angle of Incidence at Node B (in degrees)?\t");
				scanf("%lf", &phi_deg[0]);

				AS_deg[0]=-1;
				while(AS_deg[0]<0)
				{
					printf("\nAzimuth Spread (in degrees)?\t");
					scanf("%lf", &AS_deg[0]);
				}
			}
			else
			{
		
				for(j=0;j<cluster_number;j++)
				{
					if(PAS_type!=1)
					{
					
						delta_phi_deg[j]=-1;
						while(delta_phi_deg[j]<0)
						{
							printf("\nCluster %d/%d: Half Domain Definition (in degrees)?\t", j+1, cluster_number);
							scanf("%lf", &delta_phi_deg[j]);
						}

					}

					else
					{
						delta_phi_deg[j]= 90;
					}


					amplitude_cluster[j]=-1;
					while(amplitude_cluster[j]<0)
					{
						printf("\nCluster %d/%d: Linear Power?\t", j+1, cluster_number);
						scanf("%lf", &amplitude_cluster[j]);
	
					}
		
			
					printf("\nCluster %d/%d: Mean Angle of Incidence at Node B (in degrees)?\t", j+1, cluster_number);
					scanf("%lf", &phi_deg[j]);

			
					AS_deg[j]=-1;
					while(AS_deg[j]<0)
					{
						printf("\nCluster %d/%d: Azimuth Spread (in degrees)?\t", j+1, cluster_number);
						scanf("%lf", &AS_deg[j]);
					}	
				}
			}		
		}
	}



int data=(M*10)+(PAS_type*100)+cluster_number;

return data;
}

Thank you in advance, as well as sorry for my poor programming. I'm still learning...