We have to code a Hangman game for school but I am stuck on a little problem.
I have created a plain text file called wordList.txt in which I have a ID and a Word.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
| <List Version 0.1 |
---------------------------
Word ID
Hello 1
Car 2
Dog 3
Cat 4
Mice 5
| |
Now I have created a Function in which I can set a range for a random number.
Min will always be 1 and Max will be my last ID + 1.
So what I planned to do is search the text file for the Random Number and extract the word that is in the same line.
Now I saw the get() and getline() functions but was not completely sure if they do what I want because they search for a Char, so I would have to typecast the random number to a string in before and I hope to find a solution that does work without a typecast. They sound as if they extract everything BEFORE the specific Character.
getline (String where I save the Word, Big Number , ID );
That's how I imagined it, but if I enter
getline(word, 255, generateID);
it throws of errors...
TL;DR
I would appreciate if some of you would point me to a function which easily searches a Text File for a specific character and then copy the whole line IN the text file except the specified character.