SDDSlib
Loading...
Searching...
No Matches
backspace.c File Reference

Provides functionality to perform backspace operations by a specified number of characters. More...

#include "mdb.h"

Go to the source code of this file.

Functions

void backspace (long n)
 Backspace by a specified number of characters.
 

Detailed Description

Provides functionality to perform backspace operations by a specified number of characters.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
C. Saunders, R. Soliday

Definition in file backspace.c.

Function Documentation

◆ backspace()

void backspace ( long n)

Backspace by a specified number of characters.

This function outputs a specified number of backspace characters (\b) to the standard output. It dynamically allocates and reuses a buffer to store the backspace characters, optimizing memory usage for repeated calls with varying numbers of backspaces.

Parameters
nThe number of characters to backspace.

Definition at line 26 of file backspace.c.

26 {
27 static char *bspace = NULL;
28 static long n_bspace = 0;
29
30 if (n > n_bspace) {
31 register long i;
32 bspace = trealloc(bspace, sizeof(*bspace) * (n + 1));
33 for (i = n_bspace; i < n; i++)
34 bspace[i] = '\b';
35 n_bspace = n;
36 }
37 bspace[n] = 0;
38 fputs(bspace, stdout);
39 bspace[n] = '\b';
40}
void * trealloc(void *old_ptr, uint64_t size_of_block)
Reallocates a memory block to a new size.
Definition array.c:181