-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.c
80 lines (66 loc) · 3.3 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
POLITEKNIK NEGERI BANDUNG
D4 Teknik Informatika - 1A
Developer :
- Muhammad Azhar Alauddin (201524013)
- Muhammad Fauzi Rizki Hamdalah (201524015)
- Rifatia Yumna Salma (201524024)
Program : Calculator Using Binary Tree
File : history.c
IDE : DevC++, VS Code
Compiler : GCC 4.9.2
-------------------------------------- */
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "tree.h"
struct history{
char ekspresi[200];
double fresult;
char time[100];
}Record;
int saveHistory(char *expression, double result){
FILE* pFile = 0;
struct history Record;
time_t _time;
time (&_time);
struct tm *tmi;
tmi = localtime (&_time);
strftime (Record.time,100,"%d %b %Y %H:%M",tmi);
strcpy(Record.ekspresi, expression);
Record.fresult = result;
fopen_s(&pFile,"history.dat","ab+"); // append and update binary, can be read
if(!pFile)
return 1; //fopen error
fwrite(&Record,sizeof(Record),1,pFile);
fclose(pFile);
return 0;
}
int readHistory(){ //
system("cls");
FILE* pFile = 0;
int i = 1;
pFile = fopen("history.dat","ab+"); // append and update binary, can be read
if(!pFile)
return 1; //fopen error
printf("\n\n\t===============================================\n");
printf("\n\t\t History\n\n");
printf(" \t===============================================\n\n");
printf( " \xDA\xC4\xC4\xC4\xC4\xC2\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC2\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC2\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xBF\n" );
printf( " \xB3 %-3s\xB3 %-12s\xB3 %-31s\xB3 %-14s\xB3\n", "No","Time", "Arithmetic Expression", "Result");
printf( " \xC3\xC4\xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC5\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xB4\n" );
do{
fseek(pFile,(-i)*sizeof(Record),SEEK_END);
fread(&Record,sizeof(Record),1,pFile);
if(!feof(pFile) && i <= 30){
if (ceil(Record.fresult) > Record.fresult)
printf(" \xB3 %-3d\xB3 %-19s\xB3 %-39s\xB3 %-19f\xB3\n", i++, Record.time, Record.ekspresi, Record.fresult);
else
printf(" \xB3 %-3d\xB3 %-19s\xB3 %-39s\xB3 %-19d\xB3\n", i++, Record.time, Record.ekspresi, (int)Record.fresult);
}
}while(!feof(pFile) && i <= 30);
printf( " \xC0\xC4\xC4\xC4\xC4\xC1\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC1\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC1\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xD9" );
fclose(pFile);
printf("\n\n\n Press F1 on your keyboard to main menu");
return 0;
}