vfscanf
, vfwscanf
ストリームから書式化されたデータを読み出します。 これらの関数のセキュリティを強化したバージョンを使用できます。「vfscanf_s
、vfwscanf_s
」を参照してください。
構文
int vfscanf(
FILE *stream,
const char *format,
va_list argptr
);
int vfwscanf(
FILE *stream,
const wchar_t *format,
va_list argptr
);
パラメーター
stream
FILE
構造体へのポインター。
format
書式指定文字列。
arglist
可変個引数リスト。
戻り値
これらの各関数は、正常に変換および割り当てられたフィールドの数を返します。 戻り値には、読み取られたが割り当てられないフィールドは含まれません。 戻り値が 0 の場合は、代入されたフィールドがなかったことを示します。 エラーが発生した場合や、最初の変換の前にファイル ストリームの終端を検出した場合、EOF
および vfscanf
は vfwscanf
を返します。
これらの関数では、パラメーターの検証が行われます。 null ポインターのformat
場合stream
は、「パラメーターの検証」で説明されているように、無効なパラメーター ハンドラーが呼び出されます。 実行の継続が許可された場合、これらの関数は EOF
を返し、errno
を EINVAL
に設定します。
解説
vfscanf
関数は、stream
の現在位置から arglist
引数リストで指定された位置にデータを読み込みます。 リストの各引数は、format
の型指定子に対応する型の変数へのポインターにする必要があります。 format
は、入力フィールドの解釈を制御し、scanf
の引数 format
と同じ形式と機能を持ちます。format
の詳細については、「scanf
」を参照してください。
vfwscanf
関数は、vfscanf
関数のワイド文字バージョンです。vfwscanf
の format 引数は、ワイド文字列です。 ストリームが ANSI モードで開かれている場合、これらの関数の動作は同じになります。 vfscanf
では、UNICODE ストリームからの入力はサポートされていません。
汎用テキスト ルーチンのマップ
TCHAR.H のルーチン | _UNICODE と _MBCS が定義されていない |
_MBCS が定義されている |
_UNICODE が定義されている |
---|---|---|---|
_vftscanf |
vfscanf |
vfscanf |
vfwscanf |
詳細については、「書式指定フィールド: scanf
およびwscanf
関数」を参照してください。
必要条件
機能 | 必須ヘッダー |
---|---|
vfscanf |
<stdio.h> |
vfwscanf |
<stdio.h> または <wchar.h> |
互換性の詳細については、「 Compatibility」を参照してください。
例
// crt_vfscanf.c
// compile with: /W3
// This program writes formatted
// data to a file. It then uses vfscanf to
// read the various data back from the file.
#include <stdio.h>
#include <stdarg.h>
FILE *stream;
int call_vfscanf(FILE * istream, char * format, ...)
{
int result;
va_list arglist;
va_start(arglist, format);
result = vfscanf(istream, format, arglist);
va_end(arglist);
return result;
}
int main(void)
{
long l;
float fp;
char s[81];
char c;
if (fopen_s(&stream, "vfscanf.out", "w+") != 0)
{
printf("The file vfscanf.out was not opened\n");
}
else
{
fprintf(stream, "%s %ld %f%c", "a-string",
65000, 3.14159, 'x');
// Security caution!
// Beware loading data from a file without confirming its size,
// as it may lead to a buffer overrun situation.
// Set pointer to beginning of file:
fseek(stream, 0L, SEEK_SET);
// Read data back from file:
call_vfscanf(stream, "%s %ld %f%c", s, &l, &fp, &c);
// Output data read:
printf("%s\n", s);
printf("%ld\n", l);
printf("%f\n", fp);
printf("%c\n", c);
fclose(stream);
}
}
a-string
65000
3.141590
x
関連項目
ストリーム入出力
_cscanf
, _cscanf_l
, _cwscanf
, _cwscanf_l
fprintf
, _fprintf_l
, fwprintf
, _fwprintf_l
scanf
, _scanf_l
, wscanf
, _wscanf_l
sscanf
, _sscanf_l
, swscanf
, _swscanf_l
fscanf_s
, _fscanf_s_l
, fwscanf_s
, _fwscanf_s_l
vfscanf_s
, vfwscanf_s
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示