Do you mean node*? Yea I think you're right. Additionally I think I needed to malloc for the Matrix. I am getting the same bus error for invalid memory access all over the place...
Here is my main that calls 2 functions, initialize and insert:
Code:
int main(int argc, char* argv[])
{
FILE* in;
long dimension, row_index, column_index;
in = fopen(argv[1], "r");
fscanf(in, "%ld", &dimension);
double value;
Matrix* M = malloc(sizeof(Matrix));
initializeMatrix(&M, &dimension,in);
while (fscanf(in, "%ld %ld %lf", &row_index, &column_index, &value) == 3)
{
insertNode(&M, row_index, column_index, value);
}
And the reformed initialize and insert functions are:
Code:
void initializeMatrix(Matrix** M, long* dimension, FILE* in) {
(*M)->rowList = malloc(*dimension*sizeof(Node*));
(*M)->columnList = malloc(*dimension*sizeof(Node*));
int i;
for (i=0; i<*dimension; i++) {
(*M)->rowList[i] = NULL;
(*M)->columnList[i] = NULL;
}
}
void insertNode(Matrix** M, long row_index, long column_index, double value) {
Node* ptr; /*= malloc(sizeof(Node)); */
ptr->value = value; /* initialize all properties of node */
ptr->rowIndex = row_index;
ptr->columnIndex = column_index;
if ((*M)->rowList[row_index] == NULL) { /* index is empty */
ptr->rowPtr = NULL;
(*M)->rowList[row_index] = ptr;
}
else { /* ((*M)->rowList[row_index] != NULL) { index is not empty */
ptr->rowPtr = NULL;
int counter = 0;
for (counter; (*M)->columnList[counter] != NULL; counter++) {}
((*M)->columnList[counter])->colPtr = ptr;
}
if ((*M)->columnList[column_index] == NULL) {
ptr->colPtr = NULL;
(*M)->columnList[column_index] = ptr;
}
else { /* ((*M)->columnList[column_index] != NULL) { */
ptr->colPtr = NULL;
int counter = 0;
for (counter; (*M)->rowList[counter] != NULL; counter++) {}
((*M)->rowList[counter])->rowPtr = ptr;
}
}
I am now getting the bus error in insertnode...do you know why? Thanks for your help!