fscanf, _fscanf_l, fwscanf, _fwscanf_l
읽기는 스트림의 데이터를에서 포맷합니다.이러한 함수를 더 안전한 버전을 사용할 수 있습니다. see fscanf_s, _fscanf_s_l, fwscanf_s, _fwscanf_s_l.
int fscanf(
FILE *stream,
const char *format [,
argument ]...
);
int _fscanf_l(
FILE *stream,
const char *format,
locale_t locale [,
argument ]...
);
int fwscanf(
FILE *stream,
const wchar_t *format [,
argument ]...
);
int _fwscanf_l(
FILE *stream,
const wchar_t *format,
locale_t locale [,
argument ]...
);
매개 변수
stream
포인터를 FILE 구조체입니다.format
컨트롤 서식 문자열입니다.argument
선택적 인수입니다.locale
사용 하는 로캘.
반환 값
각이 함수를 성공적으로 변환 하 고 지정 된 필드 수를 반환 합니다. 반환 값이 지정 되었지만 읽을 필드는 포함 되지 않습니다.반환 값이 0 이면 필드가 없는 할당 된 나타냅니다.오류가 발생 한 경우 첫 번째 변환 전에 파일 스트림의 끝에 도달 하면 반환 값입니다 EOF 에 대 한 fscanf 및 fwscanf.
이러한 함수 매개 변수의 유효성을 검사 합니다.경우 stream 또는 format 는 null 포인터의 설명에 따라 잘못 된 매개 변수 처리기가 호출 매개 변수 유효성 검사.다음이 함수 실행 계속할 수 있는지 여부를 반환 EOF 를 설정 하 고 errno 에 EINVAL.
설명
fscanf 함수를 현재 위치에서 데이터를 읽고 stream 에 의해 주어진 위치 argument (있는 경우).각 argument 변수를 형식 지정자에 해당 하는 형식에 대 한 포인터 이어야 합니다 format.format해석 하는 입력 필드와 같은 가진 컨트롤 형성 하 고 작동 하는 format 인수에 대 한 scanf. 참조 하십시오 scanf 에 대 한 설명에 대 한 format*.*
fwscanf와이드 문자 버전입니다 fscanf. 형식 인수를 fwscanf 와이드 문자 문자열입니다.이러한 함수는 스트림에서 ANSI 모드에서 열려 있는 경우 동일 하 게 동일 하 게 동작 합니다.fscanf현재 입력 스트림에서 유니코드를 지원 하지 않습니다.
버전으로 이러한 함수는 _l 접미사는 현재 스레드의 로캘 대신 전달 된 로캘 매개 변수를 사용할 경우를 제외 하 고 동일 합니다.
일반 텍스트 루틴 매핑
TCHAR입니다.H 루틴 |
_UNICODE 및 _Mbcs가 정의 되지 않았습니다. |
_Mbcs가 정의 |
_Unicode가 정의 |
---|---|---|---|
_ftscanf |
fscanf |
fscanf |
fwscanf |
_ftscanf_l |
_fscanf_l |
_fscanf_l |
_fwscanf_l |
자세한 내용은 형식 사양을 필드 – scanf 함수 및 함수 wscanf.
요구 사항
Function |
필수 헤더 |
---|---|
fscanf, _fscanf_l |
<stdio.h> |
fwscanf, _fwscanf_l |
<stdio.h> 또는 <wchar.h> |
추가 호환성 정보를 참조 하십시오. 호환성 소개에서 합니다.
예제
// crt_fscanf.c
// compile with: /W3
// This program writes formatted
// data to a file. It then uses fscanf to
// read the various data back from the file.
#include <stdio.h>
FILE *stream;
int main( void )
{
long l;
float fp;
char s[81];
char c;
if( fopen_s( &stream, "fscanf.out", "w+" ) != 0 )
printf( "The file fscanf.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:
fscanf( stream, "%s", s ); // C4996
fscanf( stream, "%ld", &l ); // C4996
fscanf( stream, "%f", &fp ); // C4996
fscanf( stream, "%c", &c ); // C4996
// Note: fscanf is deprecated; consider using fscanf_s instead
// Output data read:
printf( "%s\n", s );
printf( "%ld\n", l );
printf( "%f\n", fp );
printf( "%c\n", c );
fclose( stream );
}
}
해당 .NET Framework 항목
System::IO::StreamReader::ReadLine. 참고 Parse 메서드 같은 System::Double::Parse.
참고 항목
참조
_cscanf, _cscanf_l, _cwscanf, _cwscanf_l
않는다면, _fprintf_l, fwprintf, _fwprintf_l
scanf, _scanf_l, wscanf, _wscanf_l