-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalc.c
42 lines (41 loc) · 821 Bytes
/
calc.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
#include "proj.h"
float calc_accuracy(int script_num)
{
FILE* fp = fopen("output.txt", "r");
FILE* fp1;
switch(script_num)
{
case 1: fp1 = fopen("script_1.txt", "r");
break;
case 2: fp1 = fopen("script_2.txt", "r");
break;
case 3: fp1 = fopen("script_3.txt", "r");
break;
}
float chars = 0;
float num_of_chars = 0;
while(True)
{
char c1 = fgetc(fp);
char c2 = fgetc(fp1);
if (c1 == EOF || c2 == EOF)
{
break;
}
if (c1 == c2)
{
chars++;
}
}
char buff[100];
fseek(fp1, 0, SEEK_SET);
while(fgets(buff, 100, fp1))
{
num_of_chars+=strlen(buff);
}
printf("Your accuracy during this session is %.1f \n", (chars/num_of_chars)*100);
getch();
fclose(fp);fclose(fp1);
system("del output.txt");
return (chars/num_of_chars)*100;
}