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
|
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
char* rightshift(char* data, size_t size) {
char* res = malloc(size * sizeof(char));
*res = ' ';
memcpy(res + 1, data, size - 1);
free(data);
return res;
}
// Graph with have a height of 10 characters and width of 12
int printgraph(int max, int inuse, char** graphdata, char prog, char* yaxis, char* xaxis) {
float percentage = ((float)inuse)/((float) max);
int percent = floorf(percentage * 10);
printf("%d\n", percent);
for (int i = 9; i > 0; i--) {
graphdata[i] = rightshift(graphdata[i], 12);
if (percent == i) {
graphdata[i][0] = '#';
}
printf("%s\n", graphdata[i]);
}
printf("End of graph\n");
return 0;
}
int main() {
int max = 50;
int arr[] = {12, 32, 40, 30, 20, 50, 10, 30};
char** data = malloc(10 * sizeof(char*));
for (int i = 0; i < 10; i++) {
*(data+i) = malloc(12 * sizeof(char));
strcpy(*(data + i), " ");
}
for (int i = 0; i < 8; i++) {
printgraph(max, arr[i], data, '#', "y", "x");
}
}
|