Originally Posted by
vart
something like
Code:
int main()
{
struct vragen quiz[100];
spelen(quiz,100);
}
void spelen(struct vragen* quiz, int maxQ)
{
int index = 0;
...
while ( fgets(line, sizeof line, file) ) /* read each line */
{
sscanf(vragen, "%s %s %s %s",
quiz[i].vraag,
quiz[i].antw,
quiz[i].antw1,
quiz[i].keuze);
i++;
if(i == maxQ)
break;
}
...
}
Thanks vart, this works like a charm!
You gave me the insight, thanks for your time & effort!
If someone is wondering; I changed my code to:
Code:
struct vragen quiz[100];
int i;
static const char filename[] = "vragen.txt"; /* the name of a file to open */
FILE *file = fopen(filename, "r+"); /* try to open the file */
if ( file )
{
char line[BUFSIZ]; /* space to read a line into */
int i = 0;
while ( fgets(line, sizeof line, file) ) /* read each line */
{
sscanf(line, "%[^]%[^;];%[^;];%[^;]",
quiz[i].vraag,
quiz[i].antw,
quiz[i].antw1,
quiz[i].keuze);
i++;
if(i == MAXVRAAG) break;
}
fclose(file);