next up previous contents
Next: frobnorm Up: リファレンスマニュアル Previous: fprintf

  
fread

【目的】
fread - ファイルからバイナリデータを読み込む
【形式】
X = fread(fd,c,type)     X = fread(fd,c,type,endian)
   Matrix X;                Matrix X;
   Integer fd;              Integer fd;
   Integer c;               Integer c;
   String type;             String type;
                            Integer endian;
【詳細】
fread(fd, c, type) は指定したファイルからバイナリデータを読み込み, それを成分とする行ベクトルを返す。読み込みに失敗すると,空行列を返す。 fd は fopen() が返すファイルディスクリプタ,c は読み込むデータ数, type は読み込むデータの型である。type には,C言語のデータの型を 文字列で指定する。次に指定できる型を示す。ただし,システムによって 符合あり(signed)の型を指定できない場合がある。
"char" : 文字 (8 bits)
"signed char" : 符合あり文字 (8 bits)
"unsigned char" : 符合なし文字 (8 bits)
"short" : 整数 (16 bits)
"signed short" : 符合あり整数 (16 bits)
"unsigned short" : 符合なし整数 (16 bits)
"int" : 整数 (16,32,64 bits)
"signed int" : 符合あり整数 (16,32,64 bits)
"unsigned int" : 符合なし整数 (16,32,64 bits)
"long" : 整数 (32 bits)
"signed long" : 符合あり整数 (32 bits)
"unsigned long" : 符合なし整数 (32 bits)
"float" : 単精度浮動小数点数 (32 bits)
"double" : 倍精度浮動小数点数 (32 bits)
fread(fd, c, type, 1)は,バイナリデータの数値形式(Endian)を変更する。
【例題】
5 個の int型のバイナリデータを読み込む。
fd = fopen("data", "r");
B = fread(fd, 5, "int");
fclose(fd);
3 個の double型のバイナリデータをEndianを変更し,読み込む。
fd = fopen("data", r");
C = fread(fd, 3, "double", 1);
fclose(fd);
【参照】
fopen(2.75), fclose(2.64), fscanf(2.82), fgets(2.69), fwrite(2.84), reshape(2.179)

next up previous contents
Next: frobnorm Up: リファレンスマニュアル Previous: fprintf
Masanobu KOGA 平成11年10月2日