-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
143 lines (124 loc) · 2.79 KB
/
main.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
int cont = 1;
char* ReadFile(char *filename)
{
char *buffer = NULL;
int string_size, read_size;
FILE *handler = fopen(filename, "rb");
if (handler)
{
// Seek the last byte of the file
fseek(handler, 0, SEEK_END);
// Offset from the first to the last byte, or in other words, filesize
string_size = ftell(handler);
// go back to the start of the file
rewind(handler);
// Allocate a string that can hold it all
buffer = (char*) malloc(sizeof(char) * (string_size + 1) );
// Read it all in one operation
read_size = fread(buffer, sizeof(char), string_size, handler);
// fread doesn't set it so put a \0 in the last position
// and buffer is now officially a string
buffer[string_size] = '\0';
if (string_size != read_size)
{
// Something went wrong, throw away the memory and set
// the buffer to NULL
free(buffer);
buffer = NULL;
}
// Always remember to close the file.
fclose(handler);
}
return buffer;
}
void StartPage()
{
char *string = ReadFile("./db/StartScreen.txt");
//char *string = ReadFile("Start.txt");
if (string)
{
puts(string);
free(string);
}
//char enterkey[1];
//scanf("%s", enterkey);
//sleep(1);
//getchar();
//system("clear");
//printf("> ");
}
void getCommand()
{
printf("> ");
char input[12];
scanf("%s", input);
if(strncmp(input,"IF",12) == 0 || strncmp(input,"if",12) == 0)
{
system("clear");
char *string = ReadFile("./db/IF.txt");
if (string)
{
puts(string);
free(string);
}
//getCommand();
}
else if(strncmp(input,"START",12) == 0 || strncmp(input,"start",12) == 0)
{
system("clear");
/*
char *string = ReadFile("./db/StartScreen.txt");
if (string)
{
puts(string);
free(string);
}
*/
StartPage();
//sleep(1);
char c = getchar();
while ((c = getchar()) != '\n' && c != EOF) { }
system("clear");
}
else if(strncmp(input,"HYDROGEN",12) == 0 || strncmp(input,"hydrogen",12) == 0)
{
system("clear");
char *string = ReadFile("./db/Hydrogen.txt");
if (string)
{
puts(string);
free(string);
}
}
else if(strncmp(input,"AC",12) == 0 || strncmp(input,"ac",12) == 0)
{
system("clear");
char *string = ReadFile("./db/AmbientComplexity.txt");
if (string)
{
puts(string);
free(string);
}
}
else if(strncmp(input,"EXIT",12) == 0 || strncmp(input,"exit",12) == 0)
{
printf("Thank you for using the TARDIS \nINFORMATION SYSTEM");
cont = 0;
}
}
int main()
{
StartPage();
getchar();
system("clear");
while(cont == 1)
{
getCommand();
}
//getCommand();
return 0;
}