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

Username:   Password: 
 RegisterRegister   
 Input Output help?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
m84uily




PostPosted: Wed Mar 11, 2009 12:01 pm   Post subject: Input Output help?

What I'm attempting to do here is get numbers from files A.txt and B.txt and put them into C.txt, however I'm having trouble with the get part.
I followed the guide : http://compsci.ca/v3/viewtopic.php?t=12972
And I do realize that I'm using a different array than the one in the tutorial, although I'm quite sure it works as another person in my class used it with success.

code:

var streamA, streamB, streamC : int
var numberA, numberB : array 1 .. 6 of string
open : streamA, "C:\\A.txt", get
open : streamB, "C:\\B.txt", get
open : streamC, "C:\\C.txt", put
get streamA, numberA
put : streamC, "This is how you put something to file"


The problem is on the line:

code:

get streamA, numberA


I get the error "illegal get item". Could someone explain to me why this is happening and how I can fix it?
Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Mar 11, 2009 12:07 pm   Post subject: RE:Input Output help?

You're missing the colon between get and streamA. You want this instead:

code:
get : streamA, numberA
m84uily




PostPosted: Wed Mar 11, 2009 12:09 pm   Post subject: Re: RE:Input Output help?

DemonWasp @ Wed Mar 11, 2009 12:07 pm wrote:
You're missing the colon between get and streamA. You want this instead:

code:
get : streamA, numberA


Thanks! But it still gives me the same error Sad
DemonWasp




PostPosted: Wed Mar 11, 2009 12:22 pm   Post subject: RE:Input Output help?

Ah, yes...and you also need to specify an element of the array. You can't just get an array, you have to get the strings that compose the array. Specifically:

code:

get : streamA, numberA(1)


etcetera.
m84uily




PostPosted: Wed Mar 11, 2009 12:26 pm   Post subject: Re: RE:Input Output help?

DemonWasp @ Wed Mar 11, 2009 12:22 pm wrote:
Ah, yes...and you also need to specify an element of the array. You can't just get an array, you have to get the strings that compose the array. Specifically:

code:

get : streamA, numberA(1)


etcetera.


Thanks, but, is there any way to get them all at once? I could definitely work with this, though.
TheGuardian001




PostPosted: Wed Mar 11, 2009 2:02 pm   Post subject: Re: Input Output help?

Yes, you can use a for statement to repeat the process for however many elements you have in your array.
code:

for i : 1 .. 4
put "This is repetition ", i, "!"
end for
andrew.




PostPosted: Wed Mar 11, 2009 3:47 pm   Post subject: RE:Input Output help?

Use "upper (arrayName)" to find the highest index you have (the number of elements). So, it would be like:
Turing:
for i : 1..upper (arrayName)
    %code
end for


Just change arrayName to the name of your array.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: