Results 1 to 2 of 2

Thread: refering to a location in a two dim array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    I have a two dim array that I created using pointers:

    int row;
    int **temp;

    temp = (int **) calloc (10, sizeof(int));

    for (row=0; row <10; ++row)
    temp[row] = (int *) calloc (10, sizeof (int));


    but I need to use a pointer in this last line instead of temp[row] any idea how?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use (*(temp + (row * sizeof(temp[0]))). One other thing though, you need to make sure that you're using proper sizes, so your first call to calloc should be:

    temp = (int **)calloc(10, sizeof(int*));

    ...since it's a pointer.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width