Thread: Help! Pointer difficulties.

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    49

    Help! Pointer difficulties.

    Here is my problem, I try to compile, it says error, *heureptr undclared.... The thing is, im trying to make *heureptr point to the adress of a row in a matrix, mat[i], wich points to the matrix mat[][24].

    The error occurs on line 34. witch is the line *heureptr = mat[i]

    Here is my code.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    float fonction(float[][24]);
    float rayonnementJour(int, float*);
    
    float vsr[12] = {0.142, 0.207, 0.298, 0.389, 0.456, 0.483, 0.467, 0.410, 0.326, 0.234, 0.158, 0.124};
    int i, h;
    
    int main()
    {     float mat[12][24];
          
          fonction(mat);
    
          i = 0;
          do
          {
          for(h = 0; h < 24; h++)
                {
                printf("&#37;f ", mat[i][h]);
                }
          printf("\n");
          i += 1;
          }while(i < 13);
          
          system("PAUSE");
          return 0;
    }
    
    float fonction(float mat[][24])
    {     
                
          for(i = 0; i < 12; i++)
                {
                     rayonnementJour(i, mat[i]);
                }
    }
    
    float rayonnementJour(int i,float *heureptr)
    {     
          float x;
          
          *heureptr + 5;
          for(h = 6; h < 19; h++)
                {
                     x = (0.2618 * (h - 12));
                     *heureptr = 2 * vsr[i] * cos(x);
                     *heureptr + 1;
                }
          
    }
    Last edited by Tyrant; 11-17-2007 at 01:11 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    float fonction(float mat[][24])
    {     int heure;
                
          for(i = 0; i < 12; i++)
                {
                     *heureptr = mat[i];
                     rayonnementJour(i, *heureptr);
                }
    }
    The compiler is complaining because this function does NOT have a heureptr, and it's also not a global variable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Code:
    ...
    float fonction(float mat[][24])
    {     int heure; /* I guess you wanted it to be int *heure;
                
          for(i = 0; i < 12; i++)
                {
                     *heureptr = mat[i];
                     rayonnementJour(i, *heureptr);
                }
    }
    ...
    C's Motto: who cares what it means? I just compile it!!

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    i removed the int heure

    i was hopping it would fixe the problem,

    *heureptr is supposed to be a pointer i shouldnt have to declare it right?

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    I changed my code to this

    Code:
    float fonction(float mat[][24])
    {     
                
          for(i = 0; i < 12; i++)
                {
                     rayonnementJour(i, mat[i]);
                }
    }
    
    float rayonnementJour(int i,float *heureptr)
    {     
          float x;
          
          *heureptr + 5;
          for(h = 6; h < 19; h++)
                {
                     x = (0.2618 * (h - 12));
                     *heureptr = 2 * vsr[i] * cos(x);
                     *heureptr + 1;
                }
          
    }
    Now its a never ending loop but its a start.

  6. #6
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by Tyrant View Post
    i removed the int heure

    i was hopping it would fixe the problem,

    *heureptr is supposed to be a pointer i shouldnt have to declare it right?
    yeah.. you are right..
    but the definition if the variable is wrong..

    what you defined is that heureptr is of type int, and NOT int pointer
    if you want to use it as a pointer you should define it as int *xyz
    C's Motto: who cares what it means? I just compile it!!

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    My code is now this, theres no more a compiling error but the output is wrong.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    float fonction(float[][24]);
    float rayonnementJour(int, float*);
    
    float vsr[12] = {0.142, 0.207, 0.298, 0.389, 0.456, 0.483, 0.467, 0.410, 0.326, 0.234, 0.158, 0.124};
    int i, h;
    
    int main()
    {     float mat[12][24];
          
          fonction(mat);
    
          i = 0;
          do
          {
          for(h = 0; h < 25; h++)
                {
                printf("&#37;f ", mat[i][h]);
                }
          printf("\n");
          i += 1;
          }while(i < 13);
          
          system("PAUSE");
          return 0;
    }
    
    float fonction(float mat[][24])
    {     
                
          for(i = 0; i < 12; i++)
                {
                     rayonnementJour(i, mat[i]);
                }
    }
    
    float rayonnementJour(int i,float *heureptr)
    {     
          float x;
          
          *heureptr + 5;
          for(h = 6; h < 19; h++)
                {
                     x = (0.2618 * (h - 12));
                     *heureptr = 2 * vsr[i] * cos(x);
                     *heureptr + 1;
                }
          
    }
    ill simplifie all the numbers.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > for(h = 0; h < 25; h++)
    This steps off the end of the array. It should be < 24

    > rayonnementJour(i, mat[i]);
    Does this even compile without any warnings for you?
    Or are you ignoring them?

    rayonnementJour(i, &mat[i]);
    would at least be consistent with the prototype and definition of the function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by gibsosmat View Post
    yeah.. you are right..
    but the definition if the variable is wrong..

    what you defined is that heureptr is of type int, and NOT int pointer
    if you want to use it as a pointer you should define it as int *xyz
    I did that

    Code:
    float fonction(float mat[][24])
    {     int *heureptr;
                
          for(i = 0; i < 12; i++)
                {    
                     *heureptr = mat[i];
                     rayonnementJour(i, *heureptr);
                }
    }
    and it compiles but then gives me a windows error and i have to end task.

    These warnings also appear.

    36 c:\docume~1\andre\mydocu~1\lcc\mini.c
    warning: assignment makes integer from pointer without a cast

    37 c:\docume~1\andre\mydocu~1\lcc\mini.c
    warning: passing arg 2 of `rayonnementJour' makes pointer from integer without a cast

  10. #10
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by Salem View Post
    > for(h = 0; h < 25; h++)
    This steps off the end of the array. It should be < 24

    > rayonnementJour(i, mat[i]);
    Does this even compile without any warnings for you?
    Or are you ignoring them?

    rayonnementJour(i, &mat[i]);
    would at least be consistent with the prototype and definition of the function.
    your right. No, no warnings, but your right.
    and i think &mat[i] and mat[i] are the same because mat[i] as to represent an adress because its a row in a matrix.

  11. #11
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Code:
    float fonction(float mat[][24])
    {     int *heureptr;// your mat[][] is type float
                
          for(i = 0; i < 12; i++)
                {    
                     *heureptr = mat[i];
                     //heureptr = mat[i]; assign address. 
                     //you are trying to put value into some pointer that is not declared
                     rayonnementJour(i, *heureptr)
                }
    }
    Last edited by gibsosmat; 11-17-2007 at 01:37 PM.
    C's Motto: who cares what it means? I just compile it!!

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    *heureptr + 5;
    That doesn't actually do anything.
    It's like saying 1+1; to which the compiler simply goes "Whoopdeedoo!".
    You need some kind of assignment or side-effect in there.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  13. #13
    Registered User
    Join Date
    Nov 2007
    Posts
    49

    My code now.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    float fonction(float[][24]);
    float rayonnementJour(int, float*);
    
    float vsr[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    int i, h;
    
    int main()
    {     float mat[12][24];
          
          fonction(mat);
    
          i = 0;
          do
          {
          for(h = 0; h < 24; h++)
                {
                printf(" &#37;f ", mat[i][h]);
                }
          printf("\n");
          i += 1;
          }while(i < 13);
          
          system("PAUSE");
          return 0;
    }
    
    float fonction(float mat[][24])
    {                 
          for(i = 0; i < 12; i++)
                {
                     rayonnementJour(i, mat[i]);
                }
    }
    
    float rayonnementJour(int i,float *heureptr)
    {     
          *heureptr + 5;
          for(h = 6; h < 19; h++)
                {
                     *heureptr = 2 * vsr[i];
                     *heureptr + 1;
                }
          
    }
    The output:

    2.000000 1.#QNAN0 7867456191839611200000000000000000.000000 0.000000 0.0000
    00 0.000000 0.000000 0.000000 0.000000 537752089363777560000000000000000000
    0.000000 0.000000 6020158900724676900000000000000000000.000000 60558914358439
    10300000000000000000000.000000 -1.#QNAN0 6056156374819358000000000000000000000
    .000000 6068373991304357700000000000000000000.000000 0.000000 1.#QNAN0 1.#QN
    AN0 6068420894376566100000000000000000000.000000 0.000000 0.000000 0.000000
    0.000000
    4.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 6070641818228166000
    000000000000000000.000000 0.000000
    6.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 6070613929914960900000000000000000000.000000 0.000000 6070400964614
    122600000000000000000000.000000 0.000000 1.#QNAN0 0.000000 60704187117225258
    00000000000000000000.000000 0.000000 0.000000 0.000000 0.000000 0.000000 6
    308463212035783600000000000000000000.000000 0.000000 0.000000
    8.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 537731490
    0415238500000000000000000000.000000 0.000000 0.000000 0.000000 0.000000 0.0
    00000 0.000000 0.000000 6024231862103210200000000000000000000.000000 0.00000
    0 0.000000 6024231862103210200000000000000000000.000000 0.000000 0.000000 0
    .000000 0.000000 0.000000
    10.000000 0.000000 6020158900724676900000000000000000000.000000 602423566505
    5010900000000000000000000.000000 -1.#QNAN0 0.000000 6026566874508830600000000
    000000000000.000000 6024186860506902100000000000000000000.000000 0.000000 0.0
    00000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 6020158900724
    676900000000000000000000.000000 6024235665055010900000000000000000000.000000 -
    1.#QNAN0 6024231862103210200000000000000000000.000000 602414629568769480000000
    0000000000000.000000 6024186860506902100000000000000000000.000000 0.000000 80
    37033551211060100000000000000000.000000
    12.000000 0.000000 0.000000 6018216226179827200000000000000000000.000000 53
    47049742334789500000000000000000000.000000 -1.#QNAN0 7889934088102935500000000
    000000000.000000 0.000000 0.000000 0.000000 0.000000 0.000000 534707572917
    2094200000000000000000000.000000 -1.#QNAN0 7889934088102935500000000000000000.
    000000 0.000000 0.000000 0.000000 5573104803271088800000000000000000000.0000
    00 0.000000 0.000000 5658224371949913800000000000000000000.000000 7889934088
    102935500000000000000000.000000 0.000000
    14.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 54947620
    94701083800000000000000000000.000000 7889934088102935500000000000000000.000000
    0.000000 0.000000 0.000000 0.000000 920466.125000 0.000000 0.000000 0.00
    0000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    16.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

    18.000000 0.000000 0.000000 6023926992133855400000000000000000000.000000 0.
    000000 6023944739242258600000000000000000000.000000 0.000000 0.000000 0.0000
    00 1.#QNAN0 0.000000 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000
    000 -0.000000 0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000
    20.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 6024190029633402700000000000000000000.000000 0.
    000000 0.000000 0.000000 0.000000
    22.000000 0.000000 6020158900724676900000000000000000000.000000 602394664071
    8158900000000000000000000.000000 -1.#QNAN0 60239447392422586000000000000000000
    00.000000 7900452864616743400000000000000000.000000 0.000000 0.000000 790045
    5959466841600000000000000000.000000 0.000000 0.000000 0.000000 7924809334889
    683200000000000000000.000000 7834164889333129100000000000000000.000000 -1.#QNA
    N0 7900601417421457600000000000000000.000000 0.000000 0.000000 0.000000 792
    4809334889683200000000000000000.000000 7834150034052657700000000000000000.00000
    0 -1.#QNAN0 7900455959466841600000000000000000.000000
    24.000000 0.000000 0.000000 0.000000 7937818227792513600000000000000000.000
    000 0.000000 1.#QNAN0 1.#QNAN0 0.000000 0.000000 0.000000 786688426354146
    1400000000000000000.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -1
    .#QNAN0 0.000000 0.000000 7988459878919600000000000000000000.000000 0.000000
    0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    0.000000 0.000000 1.#QNAN0 -222775059167508960000.000000 0.000000 0.000000
    0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 60188950530762494
    00000000000000000000.000000 5376595508699609000000000000000000000.000000 -1.#Q
    NAN0 0.000000
    Press any key to continue . . .

    somthing went terribly wrong.....

    Code:
    float rayonnementJour(int i,float *heureptr)
    {     
          *heureptr += 5;
          for(h = 6; h < 19; h++)
                {
                     *heureptr = 2 * vsr[i];
                     *heureptr++;
                }
          
    }
    is my pointer arrithmetic right? Im trying to modifie colum 6 to 18 for every row...

    should i start a new thread?
    Last edited by Tyrant; 11-17-2007 at 01:50 PM.

  14. #14
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by iMalc View Post
    That doesn't actually do anything.
    It's like saying 1+1; to which the compiler simply goes "Whoopdeedoo!".
    You need some kind of assignment or side-effect in there.
    If *heureptr dose what I want it to do:

    it represents the adresse of the first row of my matrix,
    when i go *heurptr + 5, im trying to tell *heureptr to become the adress of the 6th colum of the first row.

    then in my loop i go plus 1 so that the column goes from 6 to 18.

  15. #15
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    Quote Originally Posted by Tyrant View Post
    If *heureptr dose what I want it to do:

    it represents the adresse of the first row of my matrix,
    when i go *heurptr + 5, im trying to tell *heureptr to become the adress of the 6th colum of the first row.

    then in my loop i go plus 1 so that the column goes from 6 to 18.
    either you forgot programming in C. or you dont know how to do it..
    there are lot of problems in your code..

    avoid inliners..
    what you want to do was *heruptr+=5;..
    you better put it *heruptr = *heruptr + 5;

    *heruptr++; // not *heruptr + 1
    is *heruptr = *heruptr + 1;
    Last edited by gibsosmat; 11-17-2007 at 01:40 PM.
    C's Motto: who cares what it means? I just compile it!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM