User Tools

Site Tools


add

Table of Contents

add

The add keyword in an open function specifies that the file is to be opened for sequential access, and sets the file pointer to the end of the file. The write function then appends to (extends) the file.

See also open, write, inp, out

example

In this example a file is opened with the add clause to add the next text at the end of the file.

' SharpBASIC add programming example
' ----------------------------------
option strict;

incl "lib/sys.sbi";
incl "lib/io.sbi";

dim tfa: hnd;   ' file handle
dim flg: int;   ' flag

main do
  ' open file to add text at the end
  tfa = open(add "myfile.txt");
  ' valid file handle?
  if tfa >= 0 do
    flg = write(tfa, "This should be the next line.");
    if flg <> 0 do
      print("Error writing to file.");
    end
    close(tfa);
  else do
    print("Error opening file.");
  end
end

add.txt · Last modified: 2023/06/25 10:46 by admin