problem changing the value of the thing a pointer points to

This is a discussion on problem changing the value of the thing a pointer points to within the C Programming forums, part of the General Programming Boards category; Code: puzzle->box[box].boxmember[n].memberpos[num] = 1; memberpos is an array of integer pointers, I'm trying to set the variable that it points ...

  1. #1
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687

    problem changing the value of the thing a pointer points to

    Code:
    	puzzle->box[box].boxmember[n].memberpos[num] = 1;
    memberpos is an array of integer pointers, I'm trying to set the variable that it points to to 1, but I cant figure out where to put the *

    Code:
    *(puzzle->box[box].boxmember[n].memberpos[num]) = 1;
    results in an access violation error
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    147
    With this snippet I can't tell if you allocated space for the integer to which memberpos[ n ] points.....


    Actually, we need to see more, like the declarations, etc....

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by JVene View Post
    With this snippet I can't tell if you allocated space for the integer to which memberpos[ n ] points.....


    Actually, we need to see more, like the declarations, etc....
    I declared memberpos as an array of 9 integer pointers, n is between 0 and 8
    Code:
    typedef struct{
      int *memberpos[9];
      int *memberval;
    }member;
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Where does puzzle->box[box].boxmember[n].memberpos[num] point to - show us the allocation where you allocate the memory for that location.

    --
    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.

  5. #5
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    ignore this topic, I simply made a mistake when telling the pointers what to point at
    Last edited by ಠ_ಠ; 05-06-2009 at 08:53 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 08:59 AM
  2. pointer problem or so...
    By TL62 in forum C Programming
    Replies: 19
    Last Post: 01-12-2008, 11:45 PM
  3. CProg Fantasy Football version pi
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 155
    Last Post: 12-26-2006, 04:30 PM
  4. pointer problem
    By peterx in forum C Programming
    Replies: 3
    Last Post: 11-11-2005, 02:02 PM
  5. Problem with overwriting pointer
    By Waldo2k2 in forum C++ Programming
    Replies: 13
    Last Post: 09-29-2002, 10:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21