Hello there, im new to c-programming, and i ran accross a problem, a big big problem
the task the program was suppose to do is to read a matrix from a file that's nxn, and create upper and lower matrices with it. However, i ran into trouble when i try to pass my array to a function to initialize it.
im getting an error message of:
subscripted value is neither array nor pointer.
here is my code:
Code:
#include <stdio.h>
#include <math.h>
void
init_U (double *InputU, int n)
{
int i,j;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (i != j)
{
*InputU[i][j] = 0; /*error here*/
}
else
{
*InputU[i][j] = 1; /*error here*/
}
}
}
}
int
main(void)
{
int n, temp_value;
int i, j;
double **A, **U, **L;
FILE *inp;
inp = fopen ("d1.txt", "r");
fscanf (inp, "%d", &n);
/*------------------------------------------------------------*/
A = (double **) calloc (n,sizeof(double*));
U = (double **) calloc (n,sizeof(double*));
L = (double **) calloc (n,sizeof(double*));
for (i = 0; i < n; i++)
{
A[i] = (double *) calloc (n, sizeof(double));
U[i] = (double *) calloc (n, sizeof(double));
L[i] = (double *) calloc (n, sizeof(double));
}
/*------------------------------------------------------------*/
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
fscanf(inp, "%lf", &A[i][j]);
}
}
/*------------------------------------------------------------*/
init_U(&**U, n);
/*------------------------------------------------------------*/
fclose(inp);
return(0);
}
Any help would be greatly appreciated. Thanks a lot in advance.