bascically,my file reads an in put file which looks like this:
Expand|Select|Wrap|Line Numbers
- Is 2 1 50
- R1 2 9 500
- R2 1 0 100
- R3 2 2 900
- R4 2 1 100
then outputs the new matrix with the values from the input file... supposedly.
but i can't seem to get it to work at all.
the error is this:
c.c:40: error: subscripted value is neither array nor pointer.
and the file is this
Expand|Select|Wrap|Line Numbers
- #include <stdlib.h>
- #include <stdio.h>
- int main (void)
- {
- char R,I,line [256];
- int i,j, node1, node2, max_node=0;
- double value, **matrix, *mtx, *temp;
- FILE *program1;
- program1=fopen("text.txt", "r");
- if (program1==NULL)
- {
- printf("Unable to read file\n");
- return (0);
- }
- while (fscanf(program1,"%s %d %d %lf", line, &node1, &node2, &value)!=EOF)
- { if (max_node<node1)
- {
- max_node=node1;
- }
- else if (max_node<node2)
- {
- max_node=node2;
- }
- }
- printf("max_node %d\n", max_node); // All working, Max_node correct
- temp=(double *)malloc(max_node*max_node*sizeof(double));
- matrix=(double **)malloc(max_node*sizeof(double *));
- rewind(program1);
- //printf("%d",node1);
- while (fscanf(program1,"%s %d %d %lf", line, &node1, &node2, &value)!=EOF)
- {
- if (line[0]=='R')
- { // Resistor
- printf("%d",node1);
- temp[node1][node1] += 1.0/value; // Diagonal <<---LINE 40 - ERROR HERE
- temp[node2][node2] += 1.0/value; // Diagonal
- temp [node1][node2] -= 1.0/value; // Off-Diagonal
- temp [node2][node1] -= 1.0/value; // Off-Diagonal
- }
- else if (line[0]== 'I')
- { // Current Source
- mtx[node1]+=value;
- mtx[node2]-=value;
- }
- for (i=0;i<max_node;i++)
- {
- for(j=0;j<max_node;j++)
- {
- printf("%lf ", temp[i][j]);
- }
- printf("\t%lf\n", matrix[i]);
- }
- }*/
- }
thanks, andy