-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.c
More file actions
93 lines (85 loc) · 2.92 KB
/
main.c
File metadata and controls
93 lines (85 loc) · 2.92 KB
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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
#include "ascii.h"
#include "text_processor.h"
#include "pdf_processor.h"
#include "grader/grading.h"
int main(void) {
logo();
int choice;
printf("Choose input method:\n");
printf("1. Manual input (type text)\n");
printf("2. File input (provide text files)\n");
printf("3. PDF input mode (provide a pdf)\n\n");
printf("Enter your choice (1 or 2 or 3): ");
scanf("%d", &choice);
getchar();
switch (choice) {
case 1:
manual_input_mode();
break;
case 2:
file_input_mode();
break;
case 3:
pdf_input_mode();
// Directly prompt for user's answer file and write to CSV
{
char user_file[Max_Filename_Length];
char user_input[Max_Words * Max_Words_Length];
printf("Enter the filename for the user's answer: ");
fgets(user_file, sizeof(user_file), stdin);
user_file[strcspn(user_file, "\n")] = '\0';
FILE *file = fopen(user_file, "r");
if (!file) {
printf("Error opening file %s for reading!\n", user_file);
return 1;
}
size_t len = fread(user_input, 1, sizeof(user_input) - 1, file);
user_input[len] = '\0';
fclose(file);
write_toCSV("user_input.csv", user_input);
printf("\nCSV file 'user_input.csv' created successfully.\n");
}
break;
default:
printf("Invalid choice. Exiting.\n");
return 1;
}
// After CSVs are created, run grading
char option;
GradeBoundary current_scale[10];
memcpy(current_scale, default_grading_scale, num_grades * sizeof(GradeBoundary));
printf("\nGrading System\n");
printf("1. Use default grading scale\n");
printf("2. Configure custom grading scale\n");
printf("Choose option: ");
scanf(" %c", &option);
getchar();
if (option == '2') {
configure_grading_scale(current_scale);
}
AnswerList key = read_answers("reference.csv");
AnswerList user = read_answers("user_input.csv");
if (key.answers && user.answers) {
int matches = count_matches(key, user);
if (matches >= 0) {
printf("\nResults:\n");
printf("Correct answers: %d/%d\n", matches, key.count);
int percentage = (matches * 100) / key.count;
printf("Percentage: %d%%\n", percentage);
char grade = calculate_grade(matches, key.count, current_scale);
printf("Grade: %c\n", grade);
} else {
printf("Error: Answer counts don't match!\n");
}
} else {
printf("Error reading files!\n");
}
free_answers(key);
free_answers(user);
return 0;
}