-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhistory.c
65 lines (60 loc) · 1.1 KB
/
history.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
#include "headers.h"
extern int ff, no_hist;
extern char hist[20][N];
void history(char *str)
{
int k = no_hist - 10, c = 1;
if (k < 0)
{
if (ff)
k += 20;
else
k = 0;
}
while (1)
{
k %= 20;
if (c > 10)
break;
if (!ff && k >= no_hist)
break;
printf("%d %s", c, hist[k]);
k++;
c++;
}
}
void get_history() // get the previous history
{
FILE *fptr;
fptr = fopen("history.txt", "r");
if (fptr != NULL)
{
while (fgets(hist[no_hist], N, fptr))
{
no_hist++;
no_hist %= 20;
if (no_hist == 0)
ff++;
}
fclose(fptr);
}
}
void add_history() // update the current history
{
FILE *fptr = fopen("history.txt", "w");
int k = 0, c = 1;
if (ff)
k = no_hist;
while (1)
{
k %= 20;
if (c > 20)
break;
if (!ff && k >= no_hist)
break;
fprintf(fptr, "%s", hist[k]);
k++;
c++;
}
fclose(fptr);
}