Hello!
I have a problem to read data from a Database.txt file. The file contains the questions and answers for the quiz, and I have to read it from a file and put it to a structure so I can use it in program. I have done this with a binary file, but unfortunately I must use txt.
this is an example of questions in txt file. Of course, there are more, but I'll put just 2 of them here.
1. Koji programski jezik nije objektno orijentisan? //this is a question
1)Java
2)C++
3)Visual Basic
4)C //these 4 are the answers
4 // and this is the number of the correct answer
2. Sta je od navedenog model boja u racunaru?
1)PDF
2)DBMS
3)RGB
4)USD
3
now I will give you the structure I have made to put the data from the file in:
Code:
struct milioner
{
char question[MAX], answers[4][MAX];
int correct;
};
// and I have tried to read the file and put it in a structure with this code, but it doesn't work
FILE *ptr;
struct milioner q[BROJ];
int i,j;
ptr=fopen("Database.txt","r");
if(ptr==NULL)
printf("Error reading file.");
if(!feof(ptr))
{
for(i=0;i<BROJ;i++)
{
fgets(q[i].question,MAX+1,ptr);
for(j=0;j<4;j++)
fgets(q[i].answers[j],MAX+1,pok_dat);
fscanf(ptr,"%d",q[i].correct);
}
}
Thanks in advance!