okay, i have tried,googled and read but havn't managed to figure out where the error is.
bascically,my file reads an in put file which looks like this: -
Is 2 1 50
-
R1 2 9 500
-
R2 1 0 100
-
R3 2 2 900
-
R4 2 1 100
then it finds the max node (i.e. 9 in this case) creates a matrix by max_node,
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 - #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]);
-
}
-
}*/
-
-
}
-
i hope it's clear to where the error is.
thanks, andy
1 3385
Your temp array is of the right size, but the wrong dimension. Temp's dimension is one, not two. To make a 2 dimensional array, you need 2 steps and a loop. -
-
#include <stdlib.h>
-
-
int main (void)
-
{
-
int rows=4, cols=5;
-
double ** temp;
-
-
temp = (double**) malloc( sizeof( double *) * rows);
-
for ( int ind=0; ind<rows; ind++)
-
{
-
temp[ ind] = (double*) malloc( sizeof( double) * cols);
-
}
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: No |
last post by:
I purchased a program ( So I thought) that turned out to be just a bunch of
php scripts put together. I am getting terrible support from the author but
I am biting my tongue because I don't want...
|
by: ron |
last post by:
have been stuck on this for several days now.
I am trying to create a reverse polish calculator and I'm stuck at an
intermediate stage.
This is what I know I have to do (just not sure how to do it...
|
by: Vladimir |
last post by:
I'm running ASP on IIS 5.1 on Windows XP, the same thing works on Windows 98
with PWS.
The function below stuck the IIS - draws only frame with nothing inside and
wait for infinite. All other...
|
by: Yeren |
last post by:
We run a website with pages that are created using ASP. The website is
used by different people from different networks. For some people, the
pages are stuck. It looks like the were able to open...
|
by: Bryan Field-Elliot |
last post by:
We have a running server (v7.3) which, over time, seems to accumulate a
bunch of "stuck" PostgreSQL instances which appear to be dead inside of
a transaction. For example, "ps" reveals many of...
|
by: MLH |
last post by:
I use a mouse-down procedure to trap right mouse
clicks and CTRL-Right mouse clicks. Running the
procedure must put honey or some other sticky
substance into my keyboard because subsequent...
|
by: Mark Phillips |
last post by:
Hello,
I am having a problem in which a file can get stuck open when a thread
that is attempting to write to it gets aborted (ThreadAbortedException
occurs). The log file gets stuck open until...
|
by: MuZZy |
last post by:
Hi,
Sorry for a repeated post but i didn't receive an answer and will try to re-phrase my question:
How do i close an additional thread from the main thread,
if this additional thread is stuck...
|
by: =?Utf-8?B?TWF1cg==?= |
last post by:
My cd is stuck in the drive. I can open the drawer O K but the c d will not
come out Help me please
--
Maur
|
by: alphasahoo |
last post by:
Hi
I am working on a program which writes the output a SQL select statements from number of source tables first to a load matrix and then writes to a load.dat file.
But while writing to the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |