im making a program that:
-asks a user for their studentID and stores it as a string.
-opens questions.txt for reading
-prints to screen the question followed by each answer on a seperate line
-accepts an answer from user in letter for i.e. a,b,c,d
-writes the answer into a file with the studentID number as .txt name
-prints next question and answers
-closes at end of questions.txt
the questions.txt file contains:
The moon is made of cheese True False
The capital of California is San Diego Los Angeles Sacramento
The value of pi is closest to 9/3 36/9 314/100 22/7
my code so far is:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define INFILE "questions.txt"
#define OUTFILE "studentans.ans"
int main(int argc, char *argv[]) {
char mc;
char rt;
FILE *fin,*fout,*fid;
fin = fopen(INFILE, "r");
fout = fopen(OUTFILE, "w");
printf("enter student ID:");
getc(stdin); //accepts the id number
do
{
mc=getc(fin); //reads the questions file
if (mc=='\n') //at end of line asks for response
{
printf("\n");
printf("please enter your response as a letter:");
getc(rt);
printf("\n");
fputs(rt, fout); //writes to the answers file
}
else if(mc!='\t')
{ //prints questions to screen
printf("%c", mc);
}
while ( mc!=EOF ); //closes file and ends program
getch();
fclose (fin);
return 0;
}
any advice or help would be appreciated
im still not sure how to get the program to properly function