Raised This Month: $ Target: $400
 0% 

Help with multi-dimensional arrays


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Blackhawk
Member
Join Date: Apr 2005
Old 08-24-2005 , 14:06   Help with multi-dimensional arrays
Reply With Quote #1

If i have got an array, let's say with two dimensions, something like
Code:
Testarray[5][5]
and i would like to clear out one dimension completely, i could say something like
Code:
Testarray[3] = {0,0,0,0,0}

My question is: is there a better way, so i don't have to give every single value of this dimension? I read about something i could say
Code:
Testarray[3] = {0, ...}
but it seems no to work as expectet. Someone my have a better idea?
__________________
Outpost 104 - last hope for teamplay
Blackhawk is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 08-24-2005 , 14:33  
Reply With Quote #2

I cant understand what your asking talk to me on aim
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Blackhawk
Member
Join Date: Apr 2005
Old 08-24-2005 , 15:13  
Reply With Quote #3

Sorry, don't use AIM or IRC

My question is simple: I want to clear out(reset an entire ROW(?) of an array

Letzs say you have this simple array of 5*5 (as stated above) and filled with some values:
Code:
        0     1     2     3     4     
0      33   22   54    24   54
1      11   22   52    54   99
2      35   12   45    86   53
3      56   23   21    67   46
4      43   36   44    67   44
Now, if i use something like
Code:
Testarray[3] = {0,0,0,0,0}
on it, i wipe out the entire row. the Result would be like this:
Code:
        0     1     2     3     4     
0      33   22   54    24   54
1      11   22   52    54   99
2      35   12   45    86   53
3      0     0     0      0     0
4      43   36   44    67   44
My question was simple: Is there a more elegant way to perform the same action? As i have read in the Small/Pawn manual, you can say something like
Code:
Testarray[10] = {0, ...}
to set all 10 cells in Testarray to the value 0. But this didn't work for multidimensional arrays, at last not here - compiler error.

I hope i made myself a little bit more clear.
Thanks for your support.
__________________
Outpost 104 - last hope for teamplay
Blackhawk is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 08-24-2005 , 15:25  
Reply With Quote #4

Quote:
Originally Posted by Blackhawk
Now, if i use something like
Code:
Testarray[3] = {0,0,0,0,0}
on it, i wipe out the entire row. the Result would be like this:
Code:
        0     1     2     3     4     
0      33   22   54    24   54
1      11   22   52    54   99
2      35   12   45    86   53
3      0     0     0      0     0
4      43   36   44    67   44
Testarray[3] will look like this
Code:
       0     1     2     [3]
      #     #    #      \0
and to zero that out it will be like this
Testarray[3] = {0,0,0};
but Testarray[3] = {0,...}; should work. did u try it?
Freecode is offline
Blackhawk
Member
Join Date: Apr 2005
Old 08-24-2005 , 18:33  
Reply With Quote #5

Quote:
Originally Posted by Freecode
Quote:
Originally Posted by Blackhawk
Now, if i use something like
Code:
Testarray[3] = {0,0,0,0,0}
on it, i wipe out the entire row. the Result would be like this:
Code:
        0     1     2     3     4     
0      33   22   54    24   54
1      11   22   52    54   99
2      35   12   45    86   53
3      0     0     0      0     0
4      43   36   44    67   44
Testarray[3] will look like this
Code:
       0     1     2     [3]
      #     #    #      \0
and to zero that out it will be like this
Testarray[3] = {0,0,0};
but Testarray[3] = {0,...}; should work. did u try it?
This works, but i need the same on multidimensional arrys (as the topic says )

Defined was Testarray[5][5], so Testarray[3] selects 5 unique values, not just one. My 'problem' is: I wanted to know a smart way to 'nullify' a whole line in a multidimensional array, no matter how big the array might be, ie 32 Lines of 50 values.Testarray[3] = {0,...} works perfectly on single dimensional arrays.
__________________
Outpost 104 - last hope for teamplay
Blackhawk is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode