Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - Русский
Scilabヘルプ >> Files : Input/Output functions > mputstr

mputstr

write a single text in an open file

Syntax

mputstr(str)
mputstr(str, fid)

Arguments

fid

integer: file identifier returned by mopen(…). -1 (default) stands for the last opened file.

str

Single text to write in the file. Multilingual UTF-8 characters are accepted. str can include special formatting characters like ascii(9) (tab), ascii(10) (newline) and ascii(13) (carriage return). Sequences like "\t", "\n" and "\r" have no special meaning and are written as is.

Description

mputstr(…) writes a character string str in a binary or text file. str is buffered: It is actually written in the file only when closing this one.

Examples

myFile = tempname();
fid = mopen(myFile, "wt");

mputstr("Scilab", fid);
mgetl(myFile) // => []. "Scilab" has been buffered
mputstr(" and Xcos", fid);
mgetl(myFile) // => still []. " and Xcos" added to the buffer

// Only one text can be sent at a once:
mputstr(["Science" ; "Innovation"], fid);     // => error

mclose(fid);
mgetl(myFile) // => "Scilab and Xcos"
mdelete(myFile);

--> mputstr("Scilab", fid);
--> mgetl(myFile) // => []. "Scilab" has been buffered
 ans  =
    []

--> mputstr(" and Xcos", fid);
--> mgetl(myFile) // => still []. " and Xcos" added to the buffer
 ans  =
    []

--> // Only one text can be sent:
--> mputstr(["Science" ; "Innovation"], fid);    // => error
mputstr: Argument #1: Scalar (1 element) expected.

--> mclose(fid);
--> mgetl(myFile)
 ans  =
  "Scilab and Xcos"

Use UTF-8 and special formatting characters:

[tab, nl] = (ascii(9), ascii(10));
myFile = tempname();
fid = mopen(myFile, "wt");

mputstr("Επιστήμη", fid);
mputstr(ascii(10), fid);      // Line feed
mputstr("Τεχνολογία" + nl, fid);
mputstr(tab, fid);           // Heading tab
mputstr("innovation", fid);
mputstr(nl + "Science" + nl + tab + "technology", fid);
mclose(fid);
mgetl(myFile)

mdelete(myFile);
--> mputstr("Επιστήμη", fid);
--> mputstr(ascii(10), fid);      // Line feed
--> mputstr("Τεχνολογία" + nl, fid);
--> mputstr(tab, fid);           // Heading tab
--> mputstr("innovation", fid);
--> mputstr(nl + "Science" + nl + tab + "technology", fid);
--> mclose(fid);
--> mgetl(myFile)
 ans  =
  "Επιστήμη"
  "Τεχνολογία"
  "        innovation"
  "Science"    
  "        technology"

See also

  • mgetstr — ファイルから文字列を読み込む
  • mputl — テキストファイルに文字列を書き込む
  • mgetl — アスキーファイルから行を読み込む
  • mput — 指定したバイナリ形式でバイトまたはワードを書き込む
  • mfprintf — converts, formats, and writes data to a file
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Jul 20 11:20:44 CEST 2021