Ok I'm getting slightly insane here.
Before I begin to ask my question I will give you some code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc.h"
#define MAX_ANSWERS 3
typedef struct quest
{
char question[100];
char answer[MAX_ANSWERS][100];
int correct[MAX_ANSWERS];
struct quest* next;
} QUEST;
void make_question(QUEST** q);
void make_quiz(QUEST** phead);
int main(void)
{
QUEST* head = NULL;
make_quiz(head);
getchar();
return 0;
}
void make_quiz(QUEST** phead)
{
QUEST* q = NULL, *qprev = NULL;
char newquest = 'j';
int i=0;
phead = malloc(sizeof(QUEST));
while(newquest == 'j')
{
printf("*** Vraag %d\n-\n\n", ++i);
make_question(q);
printf("-> %s", q->question);
if (qprev!=NULL)
qprev->next = q;
else
phead = q;
qprev = malloc(sizeof(QUEST));
qprev = q;
printf("Wil je nog een vraag toevoegen ? (j/n): ");
scanf("%c", &newquest);
fflush(stdin);
}
}
void make_question(QUEST** pq)
{
int i, correctgiven=0;
char correct;
pq = malloc(sizeof(QUEST));
printf("Typ je vraag: ");
scanf("%[^\n]%*c", &pq->question);
fflush(stdin);
for(i=1;i<=MAX_ANSWERS;i++)
{
printf("\nAntwoord %d: ", i);
scanf("%[^\n]%*c", &pq->answer[i]);
fflush(stdin);
if (!correctgiven)
{
printf("Is dit antwoord correct ? (j/n)");
scanf("%c", &correct);
fflush(stdin);
if (correct == 'j')
{
correctgiven = 1;
pq->correct[i] = 1;
} else
pq->correct[i] = 0;
}
}
&pq->next = NULL;
}
I want to build a linked list of QUEST's.
First I call make_quiz() wich calls make_question() in a loop.
I give "head" along with make_quiz (byval) wich has to assign an address to head. But it just doesn't work.
What am I doing wrong ?