Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:36:34+00:00 2026-06-13T03:36:34+00:00

I am making a quiz program in c for a school project.I was storing

  • 0

I am making a quiz program in c for a school project.I was storing question and answers in a text file.The text file contains 1 question and followed by 4 choices and a correct answer(each in a new line) and so on.The code for file handling is

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
int tnum=2,mnum;
printf("Enter a file name to load the quiz from or enter dhruv.txt to load the default file\n");
printf("(For type of file and arrangement of data in it, refer to the documentation\n");
printf("WARNING: An improper quiz file may result in malfunctioning of the program.\n");
char quizfile[100];
scanf("%s",quizfile);
FILE *dj;
dj = fopen(quizfile,"r");
int test = 1;
while(dj == NULL)
{
    printf("Requested file does not exist.Please enter a valid name\n");
    scanf("%s",quizfile);
    dj = fopen(quizfile,"r");
    test++;
    if(test == 5)
    {
    exit(0);
    }
}
char line[500];
char ques[20][500],ansa[20][500],ansb[20][500],ansc[20][500],ansd[20][500],anse[20][500];
int start = 1,quesval=1,ans1=1,ans2=1,ans3=1,ans4=1,ans5=1;
while(fgets(line,sizeof line,dj) != NULL)
{
    if((start%6) == 1)
    {
        strcpy(ques[quesval],line);
        quesval++;
    }
    if((start%6) == 2)
    {
        strcpy(ansa[ans1],line);
        ans1++;
    }
    if((start%6) == 3)
    {
        strcpy(ansb[ans2],line);
        ans2++;
    }
    if((start%6) == 4)
    {
        strcpy(ansc[ans3],line);
        ans3++;
    }

    if((start%6) == 0)
    {
        strcpy(anse[ans5],line);
        ans5++;
    }

    if((start%6) == 5)
    {
        strcpy(ansd[ans4],line);
        ans4++;
    }

    start++;

}
fclose(dj);
printf("Quiz file successfully loaded\n");
printf("/t/t WELCOME TO THE QUIZ\n\n");
printf("Every team must select one of the four correct answers to the asked questions to gain points\n");
printf("Wrong answer will not be penalized\n");
for(int k =1;k<quesval;k++)
{
    int myvar;
    myvar = k%tnum;
    if(myvar == 0)
    {
        myvar = tnum;
    }
    printf("Question for TEAM %d\n\n",myvar);
    printf("%s \n A.%s B.%s C.%s D.%s\n",ques[k],ansa[k],ansb[k],ansc[k],ansd[k]);
}
getch();
}

The problem is

        if((start%6) == 0)
    {
        strcpy(anse[ans5],line);
        ans5++;
    }

The program shows File does not exist if i use this but as soon as i comment it out the program works fine.I don’t know what the error is.Please do help

EDIT:My text file looks like:

Who is the owner
dhruv
jain
kalio
polika
dhruv
who is his friend
sarika
katrina
jen
aarushi
aarushi
where is he
home
office
college
toilet
office
where will he go
home
office
college
toilet
home

EDIT
I am using Turbo c++ in windows 7 using DOSBOX..The script is updated above

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:36:36+00:00Added an answer on June 13, 2026 at 3:36 am

    It’s difficult to say without seeing your input file, but I suspect that your array declarations are backwards. For example, you have:

     char ques[500][20];
    

    This declares an array of 500 elements, where each element can be up to 20 characters. You probably want:

     char ques[20][500];
    

    This declares an array of 20 elements, where each element can be up to 500 characters.

    If your input file contains lines longer than 20 characters, then your current code is likely overwriting your arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a Quiz program. So what I want is whenever any question
I am making a quiz application with question and answer. I want to make
For a mini project I am making a quiz program My current (relavant) code
I'm making a simple quiz database, where a question has an answer and one
I am making a quiz application in J2ME. Questions and answers will come from
I am making an application for quiz. The contents text of the radio buttons
Making a simple three question PHP quiz. Each question is displayed on a page
I'm making a quiz in Actionscript 2.0. The quiz has 8 questions. Each question
Here's the quiz question: Adding two strings or making multiple copies of the same
I'm making a flash quiz which will have a series of questions. Each question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.