I am having the hardest time figuring out how to pass a pointer as an argument. All of the examples I have come across are using predefined array sizes while my array is dynamic. The following code is a simple representation of what I am trying to do in a larger project.
There are 3 files (header.h, main.c, and Display.c). In main.c I am asking the user to input several values and then it will display what is in the dynamic memory by calling Display.c. However, it will not read the information correctly.
HEADER.H
void Display(int *);
MAIN.C
#include <stdio.h>
#include <stdlib.h>
#include "header.h"
main(void)
{
int **matrices = NULL;
int size = 6;
int Index = 0;
int i = 0;
matrices = (int *) malloc(4 * sizeof(int));
if(*matrices != NULL)
{
matrices [Index] = (int *) malloc( size * sizeof(int));
if(matrices != NULL)
{
printf("Please enter several values: ");
for(i = 0; i <= size; i++)
{
scanf("%d", &matrices[Index][i]); //Would like to read the information in array matrices[Index].
}
Display(&matrices[Index]);
}
}
return 0; //Successful Termination
}
DISPLAY.C
void Display(int *matrices)
{
int i = 0;
int Index = 0;
int size = 6;
for (i = 0; i <= size; i++)
{
printf("%d", matrices[Index]);
}
}
Any help would be greatly appreciated!