I'm trying to read in a sparse matrix for a .txt file. The size of the matrix is 20 x 20 always. I need to read in the sparse matrix and store it into a regular matrix 20 x 20. I can open and read in data, but do not know how to reference the sparse into a regular matrix.
sparse.txt file
20,20
0,2-8
0,7-3
1,2-1
2,18-7
3,16-2
5,12-9
5,15-12
8,7-3
9,3-6
10,0-19
10,12-5
13,17-3
14,3-18
15,12-3
Need to read in and convert to normal matrix. Any help greatly appreciated. Thanks
CODE
int read_sparse_matrix(int read_matrix[20][20], FILE* infile){
do{
printf("Enter the file name of First Matrix\n>>");
scanf("%s", &file);
printf("Opening file %s...\n", file);
if((infile = fopen(file, "r")) == NULL){
printf("Error Opening File. Try Agian\n\n");
}
}while(infile == NULL);
x = fgetc(infile);
while(x != '\n'){
x = fgetc(infile);
}
x = fgetc(infile);
for(i=0;i<20;i++){
for(j=0;j<20;j++){
if(x == ' ' || x == '\n'){
x = fgetc(infile);
}
if(x != ' ' && x != '\n'){
A[i][j] = ((int)x)-48; //Assigns matrix A to data.
}
x = fgetc(infile);
}
}
return 0;
}