Thread: Errors!

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    13

    Errors!

    PHP Code:
    #include <iostream.h>


    void draw_map(int xint y)
    {
        
    int map[x][y];
        
    int temp_xtemp_y;

        for(
    temp_x=1;temp_x xx++)
        {
            for(
    temp_y 1temp_x yy++)
            {
                
    map[x][y]=0;
            }
        }

    }


     
    int main()
    {
         
          
    draw_map(50,50);
        
     return 
    0;

    Ive got a problem with my code, its the 2dimentional array part. Can anyone help?
    http://www.t-p-n.co.uk//
    check it out

  2. #2
    Unregistered
    Guest

    Post

    Well, just at a glance...

    The array is local to the function. You should pass the array from main() if you want to keep it; otherwise, it gets destroyed when the function goes out of function.

    Also, remember that the array starts at [0], so your initialization should look like this:

    for(temp_x=0;temp_x < x; x++)

    not: for(temp_x=1;temp_x < x; x++)

  3. #3
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    I think you did a typing mistake:
    Code:
    for (temp_y = 1; temp_x <y; y++);
    i think you meant

    Code:
    for (temp_y = 1; temp_y <y; y++)'
    If im wrong just tell me

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    13

    Nope :(

    Well Ive chnaged both of those, and tried defining it global but I still get the same errors

    theres somthing wrong with this line

    int map[x][y];
    http://www.t-p-n.co.uk//
    check it out

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > int map[x][y];
    Array sizes should be constant expressions (these are variables)
    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.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    154

    I believe if you're using a variable to define the array size you have to use the new operator to create it.

  7. #7
    Unregistered
    Guest
    hello friend
    u must know the rule for array

    use constants or constant variables in side the array index

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM