Skip to content

Instantly share code, notes, and snippets.

@GrenderG
Created February 6, 2024 12:06
Show Gist options
  • Select an option

  • Save GrenderG/13501484e9ff06fcef5edab840fbb4da to your computer and use it in GitHub Desktop.

Select an option

Save GrenderG/13501484e9ff06fcef5edab840fbb4da to your computer and use it in GitHub Desktop.

Revisions

  1. GrenderG created this gist Feb 6, 2024.
    23 changes: 23 additions & 0 deletions print_log.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    void print_log(const char *__s) {
    size_t max_length = 19;
    char __trimmed[20]; // 19 characters + 1 for null terminator.
    size_t len = strlen(__s);
    size_t i;

    // Copy characters up to max_length or until the end of the string.
    for (i = 0; i < max_length && i < len; ++i) {
    __trimmed[i] = __s[i];
    }

    // Fill the remaining space with empty spaces.
    for (; i < max_length; ++i) {
    __trimmed[i] = ' ';
    }

    // Null-terminate the string.
    __trimmed[max_length] = '\0';

    // Reset cursor position.
    gotoxy(1, 16);
    printf("%s", __trimmed);
    }