Alright... first off I hate fgets with a passion :)
Anyway, I am wanting to read a file into a 2 dimensional array and then randomly select one of those lines to output...
What am I missing here?
void displayQuestion() {
/* fp is a FILE pointer. This pointer will read text from
the "questions.txt" file */
int aRandom, i, x;
char questions[25][300];
FILE *fp = fopen("questions.txt", "rt");
if (*fp == NULL) {
printf("Invalid File\n");
}
for(x = 0; x < 25; x++){
while( fgets(questions[x], sizeof(questions), fp) != NULL) {
}
}
aRandom = (rand()%25)+1;
for(i = 0; i < 300; i++)
{
temp2=SCISR1;
temp2=SCIDRL;
while((SCISR1 & 0b10000000) != 0b10000000){}
SCIDRL = question[aRandom][i];
}
//closes the file
fclose(fp);
getButtonPress();
}
Where
for(i = 0; i < 300; i++)
{
temp2=SCISR1;
temp2=SCIDRL;
while((SCISR1 & 0b10000000) != 0b10000000){}
SCIDRL = question[aRandom][i];
}
Prints out the question onto a terminal from a certain processor.