for example, when the person selects number 5, the 5th string out of the 108 string will show, but that should be something like a search function right? i dont know if is easier to do this way or just allow a random string to show when the the person selects any number. All the strings are stored in a txt file.
I will believe each of your facts are delimited by a set of character(s). The most common for a simple text file is obviously a combination of either "\r\n", or "\r", or "\n".
You can choose to read(or slurp) all into an array, and then select based on the chosen number.
If your exercise requires you to exercise random file access nature, then you will need to find out EXACTLY where is the start of each fact(a c string).
You can either parse the file from the start till to the end for the first time, index the offset of the occurrence of the character right after the "\r\n" or "\r" or "\n". Assuming there is always a fact starting right after them except the last fact. Store the index and use it for random access when there is a chosen number.
Another naive approach every time skim thru the whole text and find the right string of each string, but this will ne sequential access, not exercising random file access.
If you really want a good way to exercise smart approach, it is how you store your text file. I would have store with a index at the top of each file as such
Code:
0:104:200:.....:1023
This is fact one
This is fact two
...
This is fact N
The first line is the offset of each C string calculated before you wrote the text file.
Another interesting way is the following
Code:
18:This is fact one
18:This is fact two
...
16:This is fact N
The beginning of each fact(C string) is the length of the following fact. You can go figure out how to traverse.
