Group: Members
Posts: 18,876
Joined: Jul 23 2006
Gold: 2,461.00
|
if it's easier, just read every line one-by-one until you reach the nth line. it's usually a much more common request, so you'd be more familiar with the libraries.
there should be libraries for file pointers to go directly to a certain spot in a file. text files are unicode which means all characters take the same amount of disk space, so it should be simple to calculate offsets for the nth character. there's nothing magical about the newline character, so you can't magically jump to it. you would have to read every character one by one to see if it's a newline. if you order your text file from shortest words to longest, on the other hand, then you can be a bit more nifty and skip reading characters. i've never done it before, so i could be wrong. but i wouldn't worry about file pointers to save performance for just an amateur hangman game. stick to the easiest code which is reading whole lines until the nth line
This post was edited by carteblanche on Jul 22 2012 09:06pm
|