two dimensional array inside a struct -- extremely WEIRD! please help, im stuck!

This is a discussion on two dimensional array inside a struct -- extremely WEIRD! please help, im stuck! within the C++ Programming forums, part of the General Programming Boards category; Code: struct MAP { int maparray1[20][56]; int maparray2[20][56]; int maparray3[20][56]; int maparray4[20][56]; int north; int south; int east; int west; ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    two dimensional array inside a struct -- extremely WEIRD! please help, im stuck!

    Code:
    struct MAP
    {
    	int maparray1[20][56];
    	int maparray2[20][56];
    	int maparray3[20][56];
    	int maparray4[20][56];
    	int north;
    	int south;
    	int east;
    	int west;
    };
    
    MAP map1;
    
    for(int a=0;a<=20;a++)
    {
    	for(int b=0;b<=56;b++)
    	{
    		map1.maparray1[a][b]=a;
    	}
    }
    this is just one way I tried to initialize the array. I also tried doing map1.maparray={0,0,0,0,.....etc.}; and all of the possible ways i knew to initialize arrays. for all of them it gives me errors like:
    c:\documents and settings\john\desktop\keldan\map.h(15) : error C2143: syntax error : missing ';' before 'for'
    c:\documents and settings\john\desktop\keldan\map.h(15) : error C2143: syntax error : missing ')' before ';'
    c:\documents and settings\john\desktop\keldan\map.h(15) : error C2143: syntax error : missing ';' before 'constant'
    c:\documents and settings\john\desktop\keldan\map.h(15) : error C2143: syntax error : missing ';' before 'constant'
    c:\documents and settings\john\desktop\keldan\map.h(15) : error C2059: syntax error : ')'
    c:\documents and settings\john\desktop\keldan\map.h(16) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\john\desktop\keldan\map.h(16) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.

    also when i try to initialize it different ways, it says things like i'm redefining MAP, and odd things like that. is there some special way for doing this? thanks.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    I don't have any problems with your given code, could you post some more?

    -Prelude
    My best code is written with the delete key.

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    try this,

    struct MAP map1;

    for(int a=0;a<=20;a++)
    {
    ...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    Two problems

    1. Your code is
    a) inside a .h file
    b) outside a function

    2. your loops are too big - you're one off the end of each array
    for(int a=0;a<=20;a++)
    should be
    for(int a=0;a<20;a++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  2. weird two dimensional array
    By stevesmithx in forum C Programming
    Replies: 4
    Last Post: 09-18-2007, 07:55 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

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