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

Username:   Password: 
 RegisterRegister   
 Arrays and files - need help please
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
helpmeagain




PostPosted: Fri May 30, 2008 10:39 pm   Post subject: Arrays and files - need help please

Hi, im fairly new to turing and for a program im wondering how I would get turing to open a file with a bunch of words.
Bascially i need it to open a file with words, then randomly pick a word and split up the letters in that word. Its for hangman. could anyone help im pretty new, I know that it has somthing to do with arrays, thnx Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri May 30, 2008 10:57 pm   Post subject: RE:[size=24]Arrays and files<<<need help please[/size]

[Turing Walkthrough] is something you want to bookmark.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
helpmeagain




PostPosted: Sat May 31, 2008 8:21 am   Post subject: Re: Arrays and files - need help please

I dont know why your so rude, im just having trouble splitting the word into letters. I can get the program to get different words but then i need to be able to split up the word into its letters.

var file_contents : flexible array 1 .. 0 of string
var stream : int
open : stream, "words.txt", get
loop
exit when eof (stream)
new file_contents, upper (file_contents) + 1
get : stream, file_contents (upper (file_contents))
end loop
loop
put file_contents (stream)
stream := stream +1
delay (1000)
end loop

now that gets me the different words but i need to split each word into its letters
Insectoid




PostPosted: Sat May 31, 2008 8:25 am   Post subject: RE:Arrays and files - need help please

code:

var letter: array 1..length (word)

for x 1..length (word)
     letter (x) := word (x)
end for


This will assign every element of 'letter' one of the letters of 'word'. To call up a random letter, use a random number and insert that into letter (?).

If you haven't done string manipulation yet, I suggest you look into it.

I had a test on string manipulation yeasterday!
helpmeagain




PostPosted: Sat May 31, 2008 8:42 am   Post subject: Re: Arrays and files - need help please

var file_contents : flexible array 1 .. 0 of string
var stream : int
var x :int

open : stream, "words.txt", get
loop
exit when eof (stream)
new file_contents, upper (file_contents) + 1
get : stream, file_contents (upper (file_contents))
end loop

var letter: array 1..length (file_contents (stream))

for x: 1..length (file_contents (stream))
letter (x):= (file_contents(stream))
end for



is my code now using what you told me. Now the only problem is the for, when ever i click run it says syntax error at 'for' expected 'of'... any ideas?
Insectoid




PostPosted: Sat May 31, 2008 9:39 am   Post subject: RE:Arrays and files - need help please

If you know this little about arrays, why are you using them?

it should read:

code:

var letter: array 1..lenght (file_contents (stream)) of string
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  [ 6 Posts ]
Jump to:   


Style:  
Search: