Issues with expression must be a point to an object error:

This is a discussion on Issues with expression must be a point to an object error: within the C Programming forums, part of the General Programming Boards category; I have two arrays declared: Code: float array1[rows][cols]; float *array2; I fill array 2 with data and now I want ...

  1. #1
    Unregistered
    Guest

    Issues with expression must be a point to an object error:

    I have two arrays declared:

    Code:
    float array1[rows][cols];
    float *array2;
    I fill array 2 with data and now I want to manipulate it in array 1 so I have:

    Code:
    for(i = 0; i < rows; i++){
    for(j = 0; j < cols; j++){
    
      array1[i][j] = array2[i][j]
    
    }
    }
    I typed this and got the old Expression must be pointer-to-object type error.

    So I tried:

    Code:
    for(i = 0; i < rows; i++){
    for(j = 0; j < cols; j++){
    
      array1[i][j] = &array2[i][j]
    
    }
    }
    Same error so I tried:

    Code:
    for(i = 0; i < rows; i++){
    for(j = 0; j < cols; j++){
    
      array1[i][j] = *array2[i][j]
    
    }
    }
    Same error... so how do I make this work?

    Thanks your help

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,547
    > I have two arrays declared:
    Nope

    > float array1[rows][cols];
    This is an array (well 2D array)

    > float *array2;
    This is an uninitialised pointer

    You can use the notation array2[x] if you want, but you've got to initialise the pointer first.

    If you really want array2[x][y], then start with float **array2
    But the same applies, you've got to initialise it.

    A board search of dynamic arrays should show you how

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

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