Hello all, I'm pretty new to coding and I'm having a little trouble in reading a list to an array from a txt file.
What I'm trying to is write 24 words from a txt file to an array and then use a number to select one at random (It's for a very simple hangman style game)
I've tried writing a procedure to read in the words and then a function which returns the random word but I've tried a few things and looked online for tutorials and I cant find one which tells me how to read from txt file to an array (I know how to do the random number generation...I think) :(
Like I said I'm pretty new so I'm not entirely sure If I'm using arrays correctly.
Here is the code I've written to read from the txtfile into the array (it doesn't work obviously though, when I print array contents to screen to test it's just blank)
Procedure ReadToArray;
Var
PhraseFile : TextFile;
FileName : String;
Begin
FileName := 'C:\Dev-Pas\MyPhrases.txt';
AssignFile (PhraseFile, FileName);
Reset (PhraseFile);
While Not EoF do
Begin
Read(PhraseFile);
For Index := 1 To 24
Do Writeln(RandomPhraseArray[Index]); {This is where I'm stuck, I'm not sure what to put on this line.}
End;
Close (PhraseFile);
End;
Thanks for any help :)