diff options
Diffstat (limited to 'graphtest.c')
-rw-r--r-- | graphtest.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/graphtest.c b/graphtest.c new file mode 100644 index 0000000..7f6e825 --- /dev/null +++ b/graphtest.c @@ -0,0 +1,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"); + } +} |