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이면 할당된 필드가 없음을 나타냅니다. 오류가 발생하거나 첫 번째 변환 전에 파일 스트림의 끝에 도달할 경우 반환 값은 vfscanfvfwscanf에 대한 EOF입니다.

이러한 함수는 해당 함수 매개 변수의 유효성을 검사합니다. null 포인터이거나 format null 포인터인 경우 stream 매개 변수 유효성 검사에 설명된 대로 잘못된 매개 변수 처리기가 호출됩니다. 계속해서 실행하도록 허용된 경우, 이러한 함수는 EOF를 반환하고 errnoEINVAL로 설정합니다.

설명

vfscanf 함수는 stream의 현재 위치에서 arglist 인수 목록에 의해 지정된 위치로 데이터를 읽습니다. 목록의 각 인수는 format의 형식 지정자에 해당되는 형식의 변수에 대한 포인터여야 합니다. format는 입력 필드의 해석을 제어하고 인수와 동일한 형식과 함수 format 를 가합니다. 에 대한 scanf설명format은 참조하세요scanf.

vfwscanfvfscanf의 와이드 문자 버전이며, vfwscanf에 대한 format 인수는 와이드 문자열입니다. 스트림이 ANSI 모드에서 열리는 경우 이러한 함수는 동일하게 작동합니다. vfscanf는 UNICODE 스트림에서의 입력을 지원하지 않습니다.

일반 텍스트 루틴 매핑

TCHAR.H 루틴 _UNICODE 정의 _MBCS 되지 않음 _MBCS 정의 _UNICODE 정의
_vftscanf vfscanf vfscanf vfwscanf

자세한 내용은 형식 사양 필드 scanfwscanf 함수를 참조하세요.

요구 사항

함수 필수 헤더
vfscanf <stdio.h>
vfwscanf <stdio.h> 또는 <wchar.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

// 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

참고 항목

스트림 I/O
_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