Errors!

This is a discussion on Errors! within the C++ Programming forums, part of the General Programming Boards category; PHP Code: #include <iostream.h> void draw_map ( int x ,  int y ) {      int map [ x ][ y ];      int temp_x ,  ...

  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
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 04:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

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