Okay, thanks ahead of time for looking at this.
First off the program is in C, not C++.
I am trying to read in from a text file... a certain question.... but i fairly suck at programming in C. I have a file pointer set up and i have it run the file open system... I want it to randomly select a question from the file and display that question.
here is the main questions..
which is more efficient?
A) doing:
fr = fopen("questions.txt", "rt");
and then creating an array to store this WHOLE file in?
ie.
char questions[400][400];
and then read them all in with nested for loops?
B) reading from a certain part of the file... like the certain line...
I am sure this is more efficient but i dont really know how to do this?
i know you can do something like this:
while (fgets(s,1000,f)!=NULL)
printf("%s",s);
but im just confused how you would implement the random number phase into that string... or if it is possible..
I will post the generic parts of my code... (can post my whole thing if requested... but its mainly a hardware program for a certain processor and might not be relevent)
FILE *fr;
void displayQuestion() {
/* fr is a FILE pointer. This pointer will read text from
the "questions.txt" file */
fr = fopen("questions.txt", "rt");
fclose(fr);
}
void main(void)
{
/* Initialize the SCI */
SCIBDL = 52;
SCICR2 = 0b00101100;
/* Enable Interupts */
EnableInterrupts;
srand((unsigned)time(NULL));
Login();
/* Loop Forever */
for(;;)
{
}
}
Now... before people say things like... why do you do void main(void)... its the way the processor program is set up... and the looping forever at the end.... both are needed (and these are new processors.... from freescale corp.)
i am basically asking for consulting advice on this system.... thank you.