-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathblackbeauty.c
87 lines (81 loc) · 2.34 KB
/
blackbeauty.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char src_file[40] = "cat /home/blackbeautyuser/blackbeauty.c";
struct ticker_tape {
long length;
char * symbol;
char tape[128];
};
void tape_machine(int user_length) {
struct ticker_tape user_tape;
user_tape.length = user_length;
user_tape.symbol = malloc(16);
strcpy(user_tape.symbol, "LANA");
memset(user_tape.tape, 0, 128);
long position = 0;
int running = 1;
int choice = 0;
int i = 0;
char value = 0;
while (running) {
puts("Ticker Tape Menu:");
puts("1) Print stock values");
printf("2) Write value at position %d\n", position);
puts("3) Seek to position");
puts("4) Change symbol");
puts("8) View Source");
puts("\n9) Exit");
scanf("%d", &choice);
if (choice == 9) {
running = 0;
}
else if (choice == 1) {
puts(user_tape.symbol);
for (i = 0; i < user_tape.length; i++) {
printf("#%d\n", user_tape.tape[i]);
}
}
else if (choice == 2) {
if (position < user_tape.length) {
printf("Enter value: ");
scanf("%d", &value);
*(user_tape.tape + position) = value;
++position;
}
else {
puts("End of tape.");
}
}
else if (choice == 3) {
printf("Enter position: ");
scanf("%ld", &position);
}
else if (choice == 4) {
printf("Change symbol: ");
read(0, user_tape.symbol, 16);
}
else if (choice == 8) {
system(src_file);
}
}
}
int main() {
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
puts("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
puts("% Nothing my sparrow, blue. %");
puts("% Oh what can I do? %");
puts("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
puts("% Stock Ticker Tape Program %");
puts("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
int user_length = 0;
printf("Please enter your ticker tape length: ");
scanf("%d", &user_length);
if (user_length > 128 || user_length < 0) {
puts("We don't have enough space to store your ticker tape.");
}
else {
tape_machine(user_length);
}
}