指定したバイナリ形式でバイトまたはワードを書き込む
mput(x [, type, fd])
浮動小数点数または整数型の数値のベクトル
スカラー: mopen
関数により返された
ファイル記述子.
-1
は,直近にオープンされたファイルを意味します.
デフォルト値は-1
です.
文字列: x
の全エントリを書き込む際に
使用されるバイナリ形式を指定.
mput
関数は,
ストリームパラメータfd
で指定した出力先にデータを
を書き込みます.
データはポインタのカレントの位置に書き込まれ,
ポインタのインジケータは前に適当に前に移動されます.
type
パラメータは変換指定子で,
以下のフラグ文字(デフォルト値 "l"
)
のどれかを指定します:
それぞれ long long, int (long int), short, unsigned long long int,
unsigned int (long int), unsigned short,
double, float, char, unsigned char を書き込みます.
書き込んだバイトは,(リトルインディアンモードで)マシンに
依存するバイナリファイルを出力するために
(リトルインディアンステータスを確認することにより)
必要に応じて自動的にスワップされます.
このデフォルトのスワップモードは,mopen
関数に
フラグswap = 0
を追加することにより抑制できます.
"l"
または"b"
文字を
type
指定子の末尾に追加することにより,
リトルインディアンまたはビッグインディアンモードで書き込むことも可能です.
例えば,"db"
はビッグインディアンモードでdoubleを書き込みます.
filen = 'test.bin'; mopen(filen,'wb'); mput(1996,'l');mput(1996,'i');mput(1996,'s');mput(98,'c'); // force little-endian mput(1996,'ll');mput(1996,'il');mput(1996,'sl');mput(98,'cl'); // force big-endian mput(1996,'lb');mput(1996,'ib');mput(1996,'sb');mput(98,'cb'); mclose(); mopen(filen,'rb'); if 1996<>mget(1,'l') then pause,end if 1996<>mget(1,'i') then pause,end if 1996<>mget(1,'s') then pause,end if 98<>mget(1,'c') then pause,end // リトルインディアンを強制 if 1996<>mget(1,'ll') then pause,end if 1996<>mget(1,'il') then pause,end if 1996<>mget(1,'sl') then pause,end if 98<>mget(1,'cl') then pause,end // ビッグインディアンを強制 if 1996<>mget(1,'lb') then pause,end if 1996<>mget(1,'ib') then pause,end if 1996<>mget(1,'sb') then pause,end if 98<>mget(1,'cb') then pause,end mclose(); | ![]() | ![]() |