#include <stdio.h>
#include<string.h>
struct Question
{
int qno;
char question[300], option1[40],option2[40],option3[40],option4[40],answer[40];
};
int main()
{
FILE *fp,*fp1;
int choice,i=0;
char c;
struct Question k;
fp=fopen("Question.txt","a");
fp1=fopen("Answer.txt","a");
x:
printf("\nQuestion No. ");
scanf("%d",&k.qno);
c-getchar();
printf("\nQuestion ");
do{
c=getchar();
k.question[i]=c;
i++;
}while(c!='\n');
k.question[i-1]='\0';
printf("\nOption1 ");
scanf("%s",k.option1);
printf("\nOption2 ");
scanf("%s",k.option2);
printf("\nOption3 ");
scanf("%s",k.option3);
printf("\nOption4 ");
scanf("%s",k.option4);
printf("\nAnswer enter in number like 1 or 2 or 3 or 4 ");
scanf("%d",&choice);
fprintf(fp,"%d\t%s\t%s\t%s\t%s\t%s\n",k.qno,k.question,k.option1,k.option2,k.option3,k.option4);
switch(choice)
{
case 1: strcpy(k.answer,k.option1); break;
case 2: strcpy(k.answer,k.option2); break;
case 3: strcpy(k.answer,k.option3); break;
case 4: strcpy(k.answer,k.option4); break;
}
fprintf(fp1,"%d\t%s",k.qno,k.answer);
printf("\nDo you want enter one more question details(1/0)");
scanf("%d",&choice);
if(choice==1)
goto x;
else
printf("\nThank you for using our program ");
fclose(fp);
return 0;
}
Comments
Post a Comment