-
Notifications
You must be signed in to change notification settings - Fork 1
/
header.h
116 lines (101 loc) · 1.68 KB
/
header.h
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
#include<sys/time.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int comperator(const void*,const void*);
/*void gotomn(int m,int n)
{
int i;
for(i=0;i<m;i++)
printf("\n");
for(i=0;i<n;i++)
printf(" ");
}*/
struct leader_b
{
char name[20];
double spd_wpm;
char a[4];
double spd_cps;
char b[4];
};
struct leader_b l1[2000];
/*void main()
{
int i;
sort();
for(i=0;i<20;i++)
{
printf("%20s\t\t%lf wpm\t\t%lf cps\n",l1[i].name,l1[i].spd_wpm,l1[i].spd_cps);
}
}*/
//struct leader_b *l1;
int comperator(const void *v1,const void *v2)
{
struct leader_b *a,*b;
a=(struct leader_b*)v1;
b=(struct leader_b*)v2;
if((b->spd_wpm)<(a->spd_wpm)) return -1;
if((b->spd_wpm)>(a->spd_wpm)) return 1;
return 0;
}
void sort()
{
char ch;
int i=0,line=0;
FILE*fs;
fs=fopen("leader_board","r");
if(fs==NULL){
printf("file could not be open\n");
exit(0);}
/*while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
if(ch=='\n')
line++;
}*/
//l1=(struct leader_b*)malloc(line*sizeof(struct leader_b));
while(fscanf(fs,"%s%lf%s%lf%s",l1[i].name,&l1[i].spd_wpm,l1[i].a,&l1[i].spd_cps,l1[i].b)!=EOF)
{
i++;
}
/*for(i=0;i<20;i++)
printf("%20s\t%lf\t%lf\n",l1[i].name,l1[i].spd_wpm,l1[i].spd_cps);*/
qsort(l1,2000,sizeof(struct leader_b),&(comperator));
fclose(fs);
}
void rank_list()
{
FILE*fr;
fr=fopen("rank_list","w");
int i;
for(i=0;i<10;i++)
{
fprintf(fr," %10d %10s%14lf \n\n",i+1,l1[i].name,l1[i].spd_wpm);
//fputc("\n",fr);
}
fclose(fr);
}
void ranking()
{
printf("Enter a key\n");
getch();
system("clear");
printf("TOP 10 in words per minute\n");
gotomn(5,0);
char ch;
FILE*fp;
fp=fopen("rank_list","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF) break;
printf("%c",ch);
}
fclose(fp);
/*getch();
system("clear");
next1();*/
}