vfscanf_s, vfwscanf_s

스트림에서 서식이 지정된 데이터를 읽습니다. 이러한 버전의 vfscanf, vfwscanf에는 CRT의 보안 기능에 설명된 대로 향상된 보안 기능이 있습니다.

구문

int vfscanf_s(
   FILE *stream,
   const char *format,
   va_list arglist
);
int vfwscanf_s(
   FILE *stream,
   const wchar_t *format,
   va_list arglist
);

매개 변수

stream
FILE 구조체에 대한 포인터입니다.

format
형식 컨트롤 문자열입니다.

arglist
가변 인수 목록입니다.

반환 값

이러한 각 함수는 성공적으로 변환되고 할당된 필드 수를 반환합니다. 반환 값에는 읽었으나 할당되지 않은 필드가 포함되지 않습니다. 반환 값이 0이면 할당된 필드가 없음을 나타냅니다. 오류가 발생하거나 첫 번째 변환 전에 파일 스트림의 끝에 도달할 경우 반환 값은 vfscanf_svfwscanf_s에 대한 EOF입니다.

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

설명

vfscanf_s 함수는 stream의 현재 위치에서 arglist 인수 목록(있는 경우)에 의해 지정된 위치로 데이터를 읽습니다. 목록의 각 인수는 format의 형식 지정자에 해당되는 형식의 변수에 대한 포인터여야 합니다. format는 입력 필드의 해석을 제어하고 인수와 동일한 형식 및 함수 format 를 가합니다. 형식 지정 필드 및 scanfwscanf 설명에 format대한 함수를 참조하세요scanf_s. vfwscanf_svfscanf_s의 와이드 문자 버전이며, vfwscanf_s에 대한 format 인수는 와이드 문자열입니다. 스트림이 ANSI 모드에서 열리는 경우 이러한 함수는 동일하게 작동합니다. vfscanf_s는 현재 UNICODE 스트림에서의 입력을 지원하지 않습니다.

더 안전한 함수(_s 접미사 포함)와 기타 버전의 주요 차이점은 더 안전한 함수의 경우 각 c, C, s, S[ 형식 필드의 문자 크기를 변수 바로 뒤의 인수로 전달해야 한다는 점입니다. 자세한 내용은 , _scanf_s_lscanf_wscanf_s_lwscanf_s너비 사양을 참조scanf_s하세요.

참고 항목

크기 매개 변수는 size_t가 아니라 unsigned 형식입니다.

일반 텍스트 루틴 매핑

TCHAR.H 루틴 _UNICODE 정의 _MBCS 되지 않음 _MBCS 정의 _UNICODE 정의
_vftscanf_s vfscanf_s vfscanf_s vfwscanf_s

요구 사항

함수 필수 헤더
vfscanf_s <stdio.h>
vfwscanf_s <stdio.h> 또는 <wchar.h>

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

예시

// crt_vfscanf_s.c
// compile with: /W3
// This program writes formatted
// data to a file. It then uses vfscanf_s to
// read the various data back from the file.

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

FILE *stream;

int call_vfscanf_s(FILE * istream, char * format, ...)
{
    int result;
    va_list arglist;
    va_start(arglist, format);
    result = vfscanf_s(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_s.out", "w+") != 0)
    {
        printf("The file vfscanf_s.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_s(stream, "%s %ld %f%c", s, _countof(s), &l, &fp, &c, 1);

        // 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_s, _cscanf_s_l, _cwscanf_s, _cwscanf_s_l
fprintf_s, _fprintf_s_l, fwprintf_s, _fwprintf_s_l
scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l
sscanf_s, _sscanf_s_l, swscanf_s, _swscanf_s_l
fscanf, _fscanf_l, fwscanf, _fwscanf_l
vfscanf, vfwscanf