7 #include "headers/utils.h"
12 return (a < b) ? a : b;
16 wrap_text(char* str, int max_width, int* lines)
23 wrapped_str = malloc(sizeof(char));
29 for (int i = 0; i < floor(strlen(str)/max_width)+1; i++) {
33 curlen = min(strlen(str_read), max_width);
34 totlen += (curlen+1); // account for new line
36 wrapped_str = realloc(wrapped_str, sizeof(char)*totlen+1); // account for null
37 strncat(wrapped_str, str_read, curlen);
38 strcat(wrapped_str, "\n");
40 str_read += max_width;