User Tools

Site Tools


clbuf

Table of Contents

clbuf

clear buffer - clears a buffer by filling it with spaces or with a specified character

syntax

clbuf(buffer [, character code])
  • buffer is an identifier of type buffer
  • character code is an optional character, used to clear (fill) the buffer with

See also cbuf, pbuf, buffer type, record

details

Buffers should be cleared/initialized before being used to store data. Especially when the data must be sent to a (standard) output device, as with the print statement, it is important to clear the buffer of non-printable characters. Also, when a buffer is copied to a string and the buffer contains the null character, it will be seen as a string terminator. By default clbuf fills a buffer with spaces (ascii code 32), but an optional character can be specified.

example

In this example a buffer is cleared with dashes (ascii code 45). A string is then converted to the buffer at offset 0 (default). Finally, the string “123” is stored starting at offset 13 (last three characters).

' SharpBASIC convert string to buffer programming example
' -------------------------------------------------------
incl "lib/sys.sbi";

' declare a string and a buffer
dim text: str;
dim buffer: byte * 16;
dim s: str;

main do

  ' clear buffer
  clbuf(buffer, 45);
  'buffer = cbuf(strep(16, 32));

  ' define the string
  text = "A new BASIC";

  ' convert string implicitly to buffer
  buffer = text;

  ' buffers can be printed
  print(buffer);

  buffer = cbuf("123", 13);
  print(buffer);

end
Output:

A new BASIC—–

A new BASIC–123

clbuf.txt · Last modified: 2023/07/23 01:05 by admin