-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.c
181 lines (157 loc) · 4.12 KB
/
question.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
int no,no1;
char ans[7],ques[5],ques1[5];
};
int main()
{
struct student s1;
FILE *fp,*fp1,*fp2;
char ch,n,i;
fp=fopen("questionpaper.txt","r");
fp1=fopen("anspaper.txt","w+");
if(fp==NULL)
{
printf("\nerror");
return 1;
}
while(!feof(fp))
{
ch=fgetc(fp);
static int count=0;
printf("%c",ch);
if(ch=='.')
{
printf("\nans:");
scanf("%c",&n);
fflush(stdin);
count++;
if(n=='a')
{
fprintf(fp1,"%d\t%c\n",count,n);
}
if(n=='b')
{
fprintf(fp1,"%d\t%c\n",count,n);
}
if(n=='c')
{
fprintf(fp1,"%d\t%c\n",count,n);
}
if(n=='d')
{
printf("\n skip this question.");
printf("\nans:");
scanf("%c",&n);
fflush(stdin);
fprintf(fp1,"%d\tskip\n",count);
}
}
}
rewind(fp1);
while(!feof(fp1))
{
int cnt=fscanf(fp1,"%d %s",&s1.no,s1.ans);
if(cnt==-1)
continue;
printf("%d\t%s\n",s1.no,s1.ans);
}
fclose(fp);
fclose(fp1);
printf("\n\n\tif you want to change the answer then enter y:");
scanf("%c",&i);
fflush(stdin);
if(i=='y')
{
fp=fopen("questionpaper.txt","r");
fp2=fopen("anspaper1.txt","w+");
while(!feof(fp))
{
ch=fgetc(fp);
static int count=0;
printf("%c",ch);
if(ch=='.')
{
printf("\nans:");
scanf("%c",&n);
fflush(stdin);
count++;
if(n=='a')
{
fprintf(fp2,"%d\t%c\n",count,n);
}
if(n=='b')
{
fprintf(fp2,"%d\t%c\n",count,n);
}
if(n=='c')
{
fprintf(fp2,"%d\t%c\n",count,n);
}
if(n=='d')
{
printf("\n skip this question.");
printf("\nans:");
scanf("%c",&n);
fflush(stdin);
fprintf(fp2,"%d\tskip\n",count);
}
}
}
fclose(fp);
fclose(fp2);
}
if(i=='y')
{
remove("anspaper.txt");
rename("anspaper1.txt","anspaper.txt");
}
if(i=='y'){
fp=fopen("anspaper.txt","r");
while(!feof(fp))
{
int cnt=fscanf(fp,"%d %s",&s1.no,s1.ans);
if(cnt==-1)
continue;
printf("%d\t%s\n",s1.no,s1.ans);
}
fclose(fp);
}
//FOR FINAL ANS
fp=fopen("anssheet.txt","r");
fp1=fopen("anspaper.txt","r");
if(fp==NULL)
{
printf("\nerror");
return 1;
}
printf("\n\n\n\tMARKS");
printf("\n\n\nQuestion no\tYour ans\tOrginal ans");
while(!feof(fp)&&!feof(fp1))
{
int cnt=fscanf(fp,"%d%s",&s1.no,s1.ques);
if (cnt==-1)
continue;
int cnt1=fscanf(fp1,"%d%s",&s1.no1,s1.ques1);
if (cnt1==-1)
continue;
if(s1.no==s1.no1)
{
if(strcmp(s1.ques,s1.ques1)==0)
{
printf("\n [%d]\t\tcorrect\t\t %s",s1.no,s1.ques);
}
if(strcmp(s1.ques,s1.ques1)!=0)
{
printf("\n [%d]\t\twrong.\t\t %s",s1.no,s1.ques);
}
}
}
fclose(fp);
fclose(fp1);
getch();
}