Could not reset pointer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • farizaz
    New Member
    • Jan 2008
    • 6

    Could not reset pointer

    Hi..
    I have tried to reset my pointer, but when I check it does not go back to the original address. I have tried at so many places but it always points to the next address whereby there is no data inside. Could someone explain. Thanks! the code I've been working on is as below..

    [CODE=cpp]for (p=k+1; p<row; p++)
    {
    char (*bptr)[5] = anothers;
    anothers = anothers + n;
    bptr = anothers;

    for (j=0; j<column; j++)
    {
    outb = (*bptr)[j];
    cout << outb;
    if ((j+1)%5 == 0)
    cout << endl;
    }

    cout << endl;
    cout << '\t' << u << '\t';

    for (j=0; j<column; j++)
    {

    char (*cptr)[5] = coll;

    if ((*aptr)[j] != (*bptr)[j])
    {
    (*cptr)[j] = '0';
    }
    else
    {
    (*cptr)[j] = (*aptr)[j];
    }

    outc = (*cptr)[j];
    cout << outc ;
    }

    cout << endl;
    }
    cout << "Pointer... :" << bptr << endl;
    }

    bptr = anothers;[/CODE]
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Originally posted by farizaz
    char (*bptr)[5] = anothers;
    anothers = anothers + n;
    You have lost the original value of anothers so you will never be able to set bptr back the original address. Make a copy of anothers and use the copy for your processing, then at the end you can set bptr to anothers and you will have your original address.

    Comment

    • farizaz
      New Member
      • Jan 2008
      • 6

      #3
      Originally posted by weaknessforcats
      You have lost the original value of anothers so you will never be able to set bptr back the original address. Make a copy of anothers and use the copy for your processing, then at the end you can set bptr to anothers and you will have your original address.
      Thanks for the feedback, i did somehow get an idea how to reset 'anothers' whiles waiting for the feedback but it goes only for 2 loops. When it got to the third, it did not give the data inside the array instead gives weird pictures like hearts and diamonds although i have checked that it is pointing at the correct address. please advice.

      for (p=k+1; p<row; p++)
      {
      cout << "Anothers" << anothers << endl;

      anothers++; //Increase row value for anothers

      cout << "N value: " << n << endl;

      bptr = anothers;

      for (j=0; j<column; j++) //Map the column values of the datasets for anothers
      {
      outb = (*bptr)[j];
      cout << outb;
      if ((j+1)%5 == 0)
      cout << endl;
      }

      cout << endl;

      for (j=0; j<column; j++)
      {
      char (*cptr)[5] = coll;

      if ((*aptr)[j] != (*bptr)[j])
      {
      (*cptr)[j] = '0';
      }
      else
      {
      (*cptr)[j] = (*aptr)[j];
      }

      outc = (*cptr)[j];
      cout << outc ;
      }

      cout << endl;
      }

      anothers = anothers - (5-n); //reset the values of anothers

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by farizaz
        anothers = anothers - (5-n); //reset the values of anothers
        5 ???????!!!!!!!

        You are just making this hard for yourself. Save the original value of anothers, like I suggested, and use it here instead of anothers - (5-n).

        Comment

        • farizaz
          New Member
          • Jan 2008
          • 6

          #5
          Originally posted by weaknessforcats
          5 ???????!!!!!!!

          You are just making this hard for yourself. Save the original value of anothers, like I suggested, and use it here instead of anothers - (5-n).
          Thanks, I have done it. But just wondering, why is it that data cannot be access from an array although it is pointing to the correct address? it give weird symbol like those on a deck of cards. Just curious to learn.

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Those weird symbols are non-printable characters interpreted as char.

            I suspect your address is not what you think it is.

            Comment

            Working...