Computer Science Canada Arrays and files - need help please |
Author: | helpmeagain [ 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 ![]() |
Author: | Tony [ 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. |
Author: | helpmeagain [ 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 |
Author: | Insectoid [ Sat May 31, 2008 8:25 am ] | ||
Post subject: | RE:Arrays and files - need help please | ||
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! |
Author: | helpmeagain [ 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? |
Author: | Insectoid [ 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:
|