Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 change name of array by concatenation
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jennil




PostPosted: Thu Dec 18, 2003 4:55 pm   Post subject: change name of array by concatenation

is it possible to change the name of an array in a for loop by concatenating a intstr value from the for loop?
and if so, must the there be a reverse strint function to transfer string back to int b4 the next loop?

thnx
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Thu Dec 18, 2003 7:25 pm   Post subject: (No subject)

i am not 100% shure if i know what you mean. do you whont to chage the name of the var the array is in or the text in a string array?
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
jennil




PostPosted: Fri Dec 19, 2003 11:03 am   Post subject: (No subject)

i want to alternate the name of the array, which has real elements. i am actually generating new arrays in every for loop and i want to change the name of the array, so i have several different named arrays: ex. array1, array2, array3.. and so on..
PaddyLong




PostPosted: Fri Dec 19, 2003 1:01 pm   Post subject: (No subject)

a 2-d array maybe?

I think I knwo what you are trying to do... just unsure of why
jennil




PostPosted: Fri Dec 19, 2003 1:53 pm   Post subject: (No subject)

yes, i noe i'm using a 2d array 2 store the information now.. however, i was just curious 2 noe whether a name of an array can b changed thru a for loop
Dan




PostPosted: Fri Dec 19, 2003 2:01 pm   Post subject: (No subject)

you cant chage the name of a varibale after you have decalered it. Alough you can move the data in one part of an array to a difrent part.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
DanShadow




PostPosted: Wed Dec 24, 2003 4:03 pm   Post subject: (No subject)

Dan is absolutely correct, you cant change the name of a variable once its declared. But instead, just move the data of one array, to another in a for statement like so:
code:

var numbers_1:array 1..10 of int
var numbers_2:array 1..10 of int
for i:1..10
numbers_1(i):=Rand.Int(1,255)
end for
for i:1..10
numbers_2(i):=numbers_1(i)
end for

Vuala
Thuged_Out_G




PostPosted: Wed Dec 24, 2003 9:26 pm   Post subject: (No subject)

i think she/he wants to make a new array each time it goes through the for loop(atleast thats what i got from it)
try this, it prolly wont work, but it should lead you in the right direction

for i:1..10
var aray + intstr(i):array 1..10 of real
end for

if that works it will go through the for loop 10 times
and make:
aray1
aray2
aray3
...
aray10

it may work, i dont know if you can declare variables in a for loop, and i dont have turing on this comp to check
Thuged_Out_G




PostPosted: Wed Dec 24, 2003 9:28 pm   Post subject: (No subject)

DanShadow wrote:

var numbers_1:array 1..10 of int
var numbers_2:array 1..10 of int
for i:1..10
numbers_1(i):=Rand.Int(1,255)
end for
for i:1..10
numbers_2(i):=numbers_1(i)
end for


and uh ya, that wouldnt work. you cant use a for loop 2x with the same var[/b]
DanShadow




PostPosted: Thu Dec 25, 2003 10:46 am   Post subject: (No subject)

Well...duh. I do it the long way to show some people (who could be new programmers) step by step how its done, not putting it all together.
Oh, and your code that makes 10 arrays in a for statement doesnt seem to work for me. Although, it looks great[/b]
Thuged_Out_G




PostPosted: Thu Dec 25, 2003 3:34 pm   Post subject: (No subject)

i didnt think it would work, but i dont have turing on this computer, so couldnt test it out to see what would need to be changed.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: