-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFile.c
229 lines (172 loc) · 5.64 KB
/
File.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#define _GNU_SOURCE
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#define QNO 30
#define totques 10
#define size 200
void asked(char option[size], const char option1[size], const char option2[size],
const char option3[size], const char option4[size],const char correct[size], const char category[size],FILE * fp,int *);
void Display();
void main()
{
char text[size],option1[size], option2[size], option3[size], option4[size], option[size], correct[size], category[size];
char empty[256][256];
int i,j,k;
int arr[QNO],x,loc;
time_t t;
char line[256];
int score = 0;
FILE * fp;
FILE * output;
fp = fopen("Quiz.txt","r");
output = fopen("NewText.txt","w");
if(fp == NULL)
{
printf("\n\n\n \t\t\t Quiz File Can't Be OPENED \t\t\t \n\n\n");
}
if(output == NULL)
{
printf("\n\n\n \t\t\t NewText File Can't Be CREATED \t\t\t \n\n\n");
}
Display();
k = 0;
for (i = 0; i < 30; i++)
{
arr[i] = 10 * i + 1;
}
for (j = 0; j < totques; j++)
{
srand((unsigned)time(&t));
x = rand() % 3;
loc = (3 * j) + x;
for (i = arr[3 * j]; i < arr[loc]; i++)
{
fgets(empty[k],sizeof(empty[k]),fp);
k++;
}
for (i = 1; i <= 10; i++)
{
fgets(line,sizeof(line),fp);
if(i==1)
{
printf("\n\n\n\n\n\nQ%d) %s",j+1,line);
fprintf(output,"Q%d) %s",j+1,line);
}
if(i==2)
{
fputs(line,output);
}
if(i == 3)
strncpy(option1,line,30);
if(i == 4)
strncpy(option2,line,30);
if(i == 5)
strncpy(option3,line,30);
if(i == 6)
strncpy(option4,line,30);
if (i >1&&i<=7)
{
printf("%s",line);
}
if (i == 8)
strncpy(correct,line,30);
if (i == 9)
strncpy(category,line,30);
}
asked(option, option1, option2, option3, option4, correct, category,output,&score);
if(j!=9)
{
if (arr[loc] + 10 < arr[3 * (j + 1)])
{
for (i = arr[loc] + 10; i < arr[3 * (j + 1)]; i++)
{
fgets(empty[k],sizeof(empty[k]),fp);
k++;
}
}
}
system("cls");
}
fprintf(output," \n You got total %d out of 40 ",score);
fclose(fp);
fclose(output);
output = fopen("Newtext.txt","r");
while(fgets(line,sizeof(line),output))
{
printf(" %s",line);
}
fclose(output);
system("pause");
}
void asked(char option[size], const char option1[size], const char option2[size], const char option3[size], const char option4[size],
const char correct[size], const char category[size],FILE * fp,int *score)
{
printf("Your Option : ");
scanf("%str",&option[0]);
option[1] = '\0';
strupr(option);
char correctanswer[size];
char wronganswer[size];
fprintf(fp,"%s \n",category);
if (option[0] == correct[0])
{
if (option[0] == option1[0])
fprintf(fp," \nYou entered correct answer : %s \n ", option1);
if (option[0] == option2[0])
fprintf(fp," \nYou entered correct answer : %s \n ", option2);
if (option[0] == option3[0])
fprintf(fp," \nYou entered correct answer : %s \n ", option3);
if (option[0] == option4[0])
fprintf(fp," \nYou entered correct answer : %s \n ", option4);
*score += 4;
fprintf(fp," \n You are awarded 4 marks for this correct answer \n ");
}
else
{
if (correct[0] == option1[0])
strncpy(correctanswer, option1,24);
if (correct[0] == option2[0])
strncpy(correctanswer, option2,24);
if (correct[0] == option3[0])
strncpy(correctanswer, option3,24);
if (correct[0] == option4[0])
strncpy(correctanswer, option4,24);
correctanswer[24] = '\0';
if (option[0] == option1[0])
strncpy(wronganswer, option1,24);
if (option[0] == option2[0])
strncpy(wronganswer, option2,24);
if (option[0] == option3[0])
strncpy(wronganswer, option3,24);
if (option[0] == option4[0])
strncpy(wronganswer, option4,24);
wronganswer[24] = '\0';
fprintf(fp," You entered : %s \n", wronganswer);
fprintf(fp," Correct answer : %s \n", correctanswer);
fprintf(fp," \n You are awarded 0 marks for this wrong answer \n ");
}
fprintf(fp," -----------------------------------------------------------------------------\n");
fprintf(fp," -----------------------------------------------------------------------------\n");
}
void Display()
{
printf("\n\n\n\n\n\n");
printf("\n\t +-------+ _______ _______ ");
printf("\n\t | | | | | / ");
printf("\n\t | | | | | / ");
printf("\n\t | | | | | / ");
printf("\n\t | // | | | | / ");
printf("\n\t | // | | | | / ");
printf("\n\t +--//---+ |_________| ___|___ /_______ ");
printf("\n\n\n\n\n\n\t\t\t PRESS ENTER TO PLAY ");
printf("\n\n\n\t\t\t\t RULES OF THE GAME : \n");
printf("\t\t\t\t 1) 4 MARKS WILL BE AWARDED FOR CORRECT \n");
printf("\t\t\t\t 2) NO MARKS WILL AWARDED FOR INCORRECT \n");
printf("\t\t\t\t 3) SCORE CARD WILL BE GIVEN AT END \n");
system("pause");
system("cls");
}