Professional Documents
Culture Documents
h>
#include <stdlib.h>
struct Node { //declaration
int row;
int column;
int value;
Node *next;
};
Node *A=(Node *)malloc(sizeof(Node)),*B=(Node *)malloc(sizeof(Node));
//declaration
if(input == NULL){
printf("Cannot open file %s. Exiting.\n", file_name);
exit(0);
}
//reads the matrix dimensions from the first line
fscanf(input, "%d %d", &row, &col);
//read matrix
for(int i = 0; i < row; ++i){
for(int j = 0; j < col; ++j){
//reads each value from this row (second line onwards)
fscanf(input, "%d", &value);
if(value==0 && j==col-1 && i==row-1){
add_node(a,row,col,0);
}
if(value == 0) continue;
//
add_node(a, i+1, j+1, value); //Adds matrix value to linked
list.
//
//The next line is for debbuging, it can be commented later
//printf("Element at (%d %d) is different than zero and it is: %d
",i,j,value);
}
//the next line is for debbuging purposes, it can be commented out
later
//printf("\n");
}
//Debug line follows:
//printLL(a,row,col);
fclose(input);
}