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

Such as? Do you have a question? Or are we supposed to figure out what you can't do psychically?

Be specific, ask questions. What do you want help with.

how do i make sure the student id becomes the output file name, and that the entered answers are printed into that specific file

>>how do i make sure the student id becomes the output file name,
using sprintf() to format the filename string

char filename[80];
sprintf(filename,"%d.txt", sudentID);

>>and that the entered answers are printed into that specific file
using fprintf() function. The second argument is the format string which tells fprintf() about the other arguments. %s tells printf() to print a standard c null-terminated string.

char answer[3] = "a"; // The answer to a question
fprintf(out,"%s\n", answer);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.