Originally Posted by
Makaila
Could somebody tell me is this the correct way to read from a txt file?
this is the content of a file:
1. Which one isn't for Object oriented programming? // question
1) Java
2) C++
3) Visual Basic
4) C // 4 answers
4 // the number of the correct answer
2. Which one is the color model for computers?
1) PDF
2) DBMS
3) RGB
4) USD
3
and I need to put this data to a structure
struct millioner
{
char question[MAX], answers[4][MAX];
int correct;
};
and I've used the following code to read this from a file:
First, let's change the indentation to make it look like, what it actually is:
Code:
FILE *ptr;
struct millioner q[BROJ];
char right[MAX];
int i,j;
ptr=fopen("Data base.txt","r");
if(ptr==NULL)
messages(0,0);
while(!feof(ptr))
{
for(i=0;i<2;i++)
{
fgets(q[i].question,MAX,ptr);
for(j=0;j<4;j++)
fgets(q[i].answers[j],MAX,ptr);
fgets(right,MAX,ptr);
q[i].correct=atoi(right[0]);
}
}
OK, try that. It's off the cuff & untested. Post back if you have a problem. BROJ is a defined constant, right?