472,793 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,793 software developers and data experts.

a bit stuck- subscripted value is neither array nor pointer...

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:

Expand|Select|Wrap|Line Numbers
  1. Is 2 1 50
  2. R1 2 9 500
  3. R2 1 0 100
  4. R3 2 2 900
  5. 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

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  4. int main (void)
  6. {    
  7.   char R,I,line [256];
  9.     int i,j, node1, node2, max_node=0;
  10.     double value, **matrix, *mtx, *temp;
  12. FILE *program1;    
  14.   program1=fopen("text.txt", "r");
  16.   if (program1==NULL)
  17.     {
  18.       printf("Unable to read file\n");
  19.       return (0);
  20.     }
  22. while (fscanf(program1,"%s %d %d %lf", line, &node1, &node2, &value)!=EOF)
  23.     {    if (max_node<node1)    
  24.     {
  25.         max_node=node1;
  26.     } 
  27.         else if (max_node<node2)
  28.     {
  29.         max_node=node2;
  30.     }    
  31.     }         
  32.     printf("max_node %d\n", max_node);        // All working, Max_node correct
  34. temp=(double *)malloc(max_node*max_node*sizeof(double));
  35. matrix=(double **)malloc(max_node*sizeof(double *));
  37. rewind(program1);
  38. //printf("%d",node1);
  39. while (fscanf(program1,"%s %d %d %lf", line, &node1, &node2, &value)!=EOF)
  40. {    
  41.      if (line[0]=='R')
  42.       { // Resistor
  43.       printf("%d",node1);
  44.     temp[node1][node1] += 1.0/value; // Diagonal  <<---LINE 40 - ERROR HERE
  45.     temp[node2][node2] += 1.0/value; // Diagonal
  46.     temp [node1][node2] -= 1.0/value; // Off-Diagonal
  47.     temp [node2][node1] -= 1.0/value; // Off-Diagonal
  48.      }
  49.     else if (line[0]== 'I')
  50.     {    // Current Source
  52.       mtx[node1]+=value;
  53.       mtx[node2]-=value;
  54.     }
  56.     for (i=0;i<max_node;i++)
  57.     {
  58.         for(j=0;j<max_node;j++)
  59.         {
  60.         printf("%lf    ", temp[i][j]);
  61.         }
  62.         printf("\t%lf\n", matrix[i]);
  63.         }
  64.     }*/
  66. }
i hope it's clear to where the error is.

thanks, andy
Dec 6 '07 #1
1 3356
463 Expert 256MB
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.
Expand|Select|Wrap|Line Numbers
  2.  #include <stdlib.h>
  4.  int main (void)
  5.  {   
  6.     int rows=4, cols=5;
  7.     double ** temp;
  9.     temp = (double**) malloc( sizeof( double *) * rows);
  10.     for ( int ind=0; ind<rows; ind++)
  11.     {
  12.         temp[ ind] = (double*) malloc( sizeof( double) * cols);
  13.     }
  14. }
Dec 6 '07 #2

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: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.