added helper functions

This commit is contained in:
2026-06-06 01:09:53 +02:00
parent c54b3f874b
commit 73bb260fec
15 changed files with 621 additions and 12 deletions

64
draw.c Normal file
View File

@@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "draw.h"
void drawEdges() {
for (int i = 0; i < WIDTH; i++) {
printf("%c", SEPERATION_CHAR);
}
printf("\n");
}
void drawTitle(char* title) {
// put seperation_char at start and end
printf("%c", SEPERATION_CHAR);
// calculate amount of spaces before and after the word
int spacing = (WIDTH - 2 - strlen(title)) / 2;
for (int i = 0; i < spacing; i++) {
printf(" ");
}
printf("%s", title);
if (strlen(title) % 2 != WIDTH % 2) {
spacing += 1;
}
for (int i = 0; i < spacing; i++) {
printf(" ");
}
printf("%c\n", SEPERATION_CHAR);
}
void drawEmptyLines(const int amount) {
for (int i = 0; i < amount; i++) {
printf("%c", SEPERATION_CHAR);
for (int j = 0; j < WIDTH - 2; j++) {
printf(" ");
}
printf("%c\n", SEPERATION_CHAR);
}
}
char** splitByNewline(char *str, int *lineCount) {
int maxLines = 100;
char **lines = malloc(maxLines * sizeof(char*));
int count = 0;
char *token = strtok(str, "\n");
while (token != NULL) {
lines[count] = token; // Store the pointer to this line
count++;
if (count >= maxLines) {
break; // Safety check so we don't overflow our array
}
token = strtok(NULL, "\n");
}
*lineCount = count; // Pass the total count back to the caller
return lines;
}