Someone posted a question as to how a program could be written to ask questions, obtain an answer, and then compare it the user answer to the correct answer. I replied with a method of hard coding the questions and answers into an array, but thought about it in more detail. It might be useful to have an instructor be able to enter his or her questions and then the correct answer and store that info into a dat file. So I thought about that for awhile, but couldn't figure out exactly how to store the questions correctly... I got null pointer assignments. Anyway, I came up with something like
Code:
#include <stdio.h>
#define MAXNUM 4 // four questions & answers
#define MAXLEN 80 // max size of question string
int main(void)
{
char *userQuestions[MAXNUM][MAXLEN];
int userAnswers[MAXNUM]; // assume an int value for now.
int i;
for(i = 0; i < MAXNUM; i++)
{
printf("Enter question %d: ", i);
// I debated over scanf or fgets but I'm not sure how
// to read in the string
scanf("%s", &userQuestions[i][MAXLEN]);
printf("Enter the answer for question %d: ", i);
scanf("%d", &userAnswers[i]);
}
..... other code
Any ideas as to how to approach this would be appreicated.