473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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>
  3.  
  4. int main (void)
  5.  
  6. {    
  7.   char R,I,line [256];
  8.  
  9.     int i,j, node1, node2, max_node=0;
  10.     double value, **matrix, *mtx, *temp;
  11.  
  12. FILE *program1;    
  13.  
  14.   program1=fopen("text.txt", "r");
  15.  
  16.   if (program1==NULL)
  17.     {
  18.       printf("Unable to read file\n");
  19.       return (0);
  20.     }
  21.  
  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
  33.  
  34. temp=(double *)malloc(max_node*max_node*sizeof(double));
  35. matrix=(double **)malloc(max_node*sizeof(double *));
  36.  
  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
  51.  
  52.       mtx[node1]+=value;
  53.       mtx[node2]-=value;
  54.     }
  55.  
  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.     }*/
  65.  
  66. }
  67.  
i hope it's clear to where the error is.

thanks, andy
Dec 6 '07 #1
1 3385
RRick
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
  1.  
  2.  #include <stdlib.h>
  3.  
  4.  int main (void)
  5.  {   
  6.     int rows=4, cols=5;
  7.     double ** temp;
  8.  
  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. }
  15.  
Dec 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
1
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...
2
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...
3
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...
2
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...
8
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...
0
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...
12
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...
4
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
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...

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.