rewind() — 현재 파일 위치 조정
형식
#include <stdio.h>
void rewind(FILE *stream);
언어 레벨
ANSI
스레드세이프
예
설명
rewind()
함수는 stream과 연관된 파일 포인터를 파일
시작으로 이동합니다.
rewind()
함수에 대한 호출은 다음과 같습니다.
(void)fseek(stream, 0L, SEEK_SET);
rewind() 함수가 stream에 대한 오류 인디케이터도 지우는 점은 제외하고 동일합니다.
rewind() 함수는 type=record로 열린 파일에 대해 지원되지 않습니다.
리턴값
리턴값이 없습니다.
errno의 값은 다음으로 설정될 수 있습니다.
- 값
- 의미
- EBADF
- 파일 포인터 또는 설명자는 유효하지 않습니다.
- ENODEV
- 연산이 잘못된 장치에서 시도되었습니다.
- EIOERROR
- 회복 불가능한 I/O 오류가 발생했습니다.
- EIORECERR
- 회복 가능한 I/O 오류가 발생했습니다.
예
이 예는 입력과 출력을 위해 파일
myfile을 먼저 엽니다. 정수를 파일에 쓰고,
rewind()를 사용하여 파일 포인터를 파일의 시작으로 이동한 다음 데이터를 읽습니다.
#include <stdio.h>
FILE *stream;
int data1, data2, data3, data4;
int main(void)
{
data1 = 1; data2 = -37;
/* Place data in the file */
stream = fopen("mylib/myfile", "w+");
fprintf(stream, "%d %d\n", data1, data2);
/* Now read the data file */
rewind(stream);
fscanf(stream, "%d", &data3);
fscanf(stream, "%d", &data4);
printf("The values read back in are: %d and %d\n",
data3, data4);
}
/******************** Output should be similar to: **************
The values read back in are: 1 and -37
*/