diff options
author | Josh <joshua.liu@sourceobby.com> | 2025-01-21 09:54:43 -0500 |
---|---|---|
committer | Josh <joshua.liu@sourceobby.com> | 2025-01-21 09:54:43 -0500 |
commit | d03cb95135eae338d8fa864f05325cd5cd5eb7e6 (patch) | |
tree | e7cbb92c668c7086b04448908f790539a3ec3ae0 | |
parent | 89810561a269ad6d11ecae58c49e209314e14c1a (diff) |
feat: testing printing cpu core functionality and graphing behavior
-rw-r--r-- | graphtest.c | 41 | ||||
-rw-r--r-- | squaretest.c | 7 |
2 files changed, 48 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"); + } +} diff --git a/squaretest.c b/squaretest.c new file mode 100644 index 0000000..e518fe9 --- /dev/null +++ b/squaretest.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main() { + for (int i = 0; i < 10; i++) { + printf("+---+\n| |\n+---+"); + } +} |