473,320 Members | 1,887 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,320 software developers and data experts.

This program is linking but not giving any output

Expand|Select|Wrap|Line Numbers
  1. class Link
  2. {
  3.    public:
  4. // function to calculate DH parameter
  5.       double DHP() 
  6.       {
  7.          int rows=4;
  8.          double **R = (double **) malloc(rows * sizeof(double *));
  9.  
  10.          if (joint_type == 0)
  11.          {    
  12.             // theta = q + joint_offset;    
  13.             R[0][0] = cos(theta);
  14.             R[1][0] = sin(theta);
  15.             R[2][0] = 0.0;
  16.             R[3][0] = 0.0;
  17.             R[0][1] = -cos(alpha)*sin(theta);
  18.             R[1][1] = cos(alpha)*cos(theta);
  19.             R[2][1] = sin(alpha);
  20.             R[3][1] = 0.0;
  21.             R[0][2] = sin(alpha)*sin(theta);
  22.             R[1][2] = -sin(alpha)*cos(theta);
  23.             R[2][2] = cos(alpha);
  24.             R[3][2] = 0.0;    
  25.             R[0][3] = a*cos(theta);
  26.             R[1][3] = a*sin(theta);
  27.             R[2][3] = d;
  28.             R[3][3] = 1.0;
  29.          }
  30.          else
  31.          {
  32.             // d = q +joint_offset;
  33.             R[0][0] = cos(theta);
  34.             R[1][0] = sin(theta);
  35.             R[2][0] = 0.0;
  36.             R[3][0] = 0.0;
  37.             R[0][1] = -cos(alpha)*sin(theta);
  38.             R[1][1] = cos(alpha)*cos(theta);
  39.             R[2][1] = sin(alpha);
  40.             R[3][1] = 0.0;
  41.             R[0][2] = sin(alpha)*sin(theta);
  42.             R[1][2] = -sin(alpha)*cos(theta);
  43.             R[2][2] = cos(alpha);
  44.             R[3][2] = 0.0;    
  45.             R[0][3] = 0.0;
  46.             R[1][3] = 0.0;
  47.             R[2][3] = d;        
  48.             R[3][3] = 1.0;
  49.          }
  50.  
  51.          return(**R);
  52.       }
  53. };
  54.  
  55. int main() 
  56. {
  57.    Link links[6] = { Link(0,90,0,0,-90,-160,160,10),
  58.                      Link(0,0,149.09,431.8,0,-225,45,10),
  59.                      Link(0,90,0,-20.32,90,-45,225,10),
  60.                      Link(0,-90,0,0,-90,-110,170,10),
  61.                      Link(0,0,0,0,90,-100,100,10),
  62.                      Link(0,0,56.25,0,0,-266,266,10) };
  63.    double dhpl1[4][4], dhpl2[4][4],dhpl[4][4];                    
  64.    **dhpl1 = links[0].DHP();                    
  65.    **dhpl2 = links[1].DHP();
  66.  
  67.    int i, j, k, val;
  68.    for (i=0; i<4; i++)
  69.    {
  70.       for (j=0; j<4; j++) 
  71.       {
  72.          val = 0;
  73.          for (k=0; k<4; k++) 
  74.          {
  75.             val += dhpl1[i][k] * dhpl2[k][j];
  76.          }
  77.          dhpl[i][j] = val;
  78.       }
  79.    }
  80.  
  81.    cout << dhpl[1][1];
  82.  
  83.    return(0);
  84. }
<MODERATOR NOTE: Some code has been removed. See our FAQ for the reasons.>

no error in compiling and linking..but no output also..
please help
Feb 28 '07 #1
7 1435
Ganon11
3,652 Expert 2GB
Well, the DHP() function you are calling returns one double value, and this value is assigned to one spot in dhpl1 and dhpl2 - but then your loops try to add every element of dhpl1 and dhpl2 to dhpl. Maybe your DHP() function should be returning a double** rather than a double, so that the pointers in main() are assigned all the values generated in the DHP() function.

Also, please don't double post. The second thread you created on the same topic has been deleted.
Feb 28 '07 #2
thanks alot for ur response..
but i tried with changes but its not working..its returning garbage value..
can u please tell me where should i do changes to make it run...
about another thread..that was similar program without classes..
i was fed up with this program so i tried to write using functions..but it also didnt wok..please tell me where to change in the program...
Feb 28 '07 #3
Ganon11
3,652 Expert 2GB
Something I missed in the first run (thanks to Banfa for pointing this out) is that your initialization for R is incorrect. You properly set the rows of the array to double* pointers, but then you need to initialize each row (each double*) to an array of doubles. You can use a for loop and another malloc() call to do this.
Feb 28 '07 #4
Hello!
I initialized R as per the directions..
its linking without output...
Is initializtion is o.k.?
please help

Expand|Select|Wrap|Line Numbers
  1. class Link
  2. {
  3.    public:
  4.  
  5. // function to calculate DH parameter
  6.       double DHP() 
  7.       {   
  8.          double rows=4; double **R ;
  9. //    double **R = (double **) malloc(rows * sizeof(double *));
  10.          for(int i=0;i<4;i++)
  11.          {
  12.             for(int j=0;j<4;j++)    
  13.                R  =  (double **) malloc(rows * sizeof(double **));    
  14.          }
  15.  
  16.          if (joint_type == 0)
  17.          {    
  18.             // theta = q + joint_offset;
  19.             R[0][0] = cos(theta);
  20.             R[1][0] = sin(theta);
  21.             R[2][0] = 0.0;
  22.             R[3][0] = 0.0;
  23.             // other such assignment statements...
  24.          }
  25.          else
  26.          {
  27.             // d = q +joint_offset;
  28.             R[0][0] = cos(theta);
  29.             R[1][0] = sin(theta);
  30.             R[2][0] = 0.0;
  31.             R[3][0] = 0.0;
  32.             // other such assignment statements...
  33.          }
  34.          return(**R);
  35.       }
  36. };
  37.  
  38. int main() 
  39. {
  40.        Link links[6] = {
  41.                                 Link(0,90,0,0,-90,-160,160,10),
  42.                                 Link(0,0,149.09,431.8,0,-225,45,10),
  43.                                 Link(0,90,0,-20.32,90,-45,225,10),
  44.                                 Link(0,-90,0,0,-90,-110,170,10),
  45.                                 Link(0,0,0,0,90,-100,100,10),
  46.                                 Link(0,0,56.25,0,0,-266,266,10)
  47.                     };
  48. double dhpl1[4][4], dhpl2[4][4],dhpl[4][4];                    
  49. **dhpl1 = links[0].DHP();                    
  50. **dhpl2 = links[1].DHP();
  51.  
  52.  
  53. int i, j, k;
  54.  
  55.     for (i=0; i<4; i++)
  56.     {
  57.      for (j=0; j<4; j++) 
  58.         {
  59.          dhpl[i][j] = 0;
  60.             for (k=0; k<4; k++) 
  61.             {
  62.               dhpl[i][j] = dhpl[i][j] + dhpl1[i][k] * dhpl2[k][j];
  63.             }
  64.  
  65.          }
  66.     }
  67.  
  68.  
  69. cout  << dhpl[0][0];
  70.  
  71.     return(0);
  72. }
Mar 1 '07 #5
Ganon11
3,652 Expert 2GB
Actually, R should be initialized using something like this:

Expand|Select|Wrap|Line Numbers
  1. R = (double**)malloc(/*ROWS * Size of a double**/);
  2. for (/*EACH ROW*/) {
  3.    R[index] = (double*)malloc(/*COLS * Size of a double*/);
  4. }
Mar 1 '07 #6
int rows=16, cols=16;
double **R ;

R = (double**)malloc(rows*sizeof(double *));

for( i=0;i<rows;i++)
{
R[i]= (double*)malloc(cols*sizeof(double));

}

this is how i initialized the R..
still its giving only garbage value as output..
Mar 1 '07 #7
I used vectors instead of pointer...
its working nicely..
thanks for all ur response
Mar 2 '07 #8

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

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
37
by: Curt | last post by:
If this is the complete program (ie, the address of the const is never taken, only its value used) is it likely the compiler will allocate ram for constantA or constantB? Or simply substitute the...
23
by: Ricky | last post by:
thanks for the replysir. i have made this code so far in declaring the NFA. In fact i do know what am i supposed to do , i just cant get it right. please have a look at the following code and tell...
1
by: Orgad | last post by:
I wrote a simple program (in which I reused a data structure), but it refuses to link. Can anyone here please help me? Notice that Region2D.cpp IS in the compilation, and the "unresolved"...
29
by: tele-commuter | last post by:
Hi folks, I want to understand how exactly is an image(compiled c code and loaded into memory) stored in memory. What exactly is a linker script? I work with a lot of c code on a daily...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
4
by: sulekhasweety | last post by:
Hi, can any one give a brief outline of the different stages in the execution of a C program , in terms of compilation, pre-processing, linking etc
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome –...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.