fseek : 파일 포인터 (위치) 이동하기
등록자 : cpueblo (유광희), 2008-10-16
소스 출처 : http://www.java2s.com/Code/C/stdio.h/fseekmovesthefilepositionpointer.htm
fseek
Header file: stdio.h
Declaration: int fseek(FILE *stream, long int offset, int origin);
Return: zero on success or nonzero on failure.
'origin' must be one of:
정의값 의미
SEEK_SET: 파일의 시작 위치부터 계산
SEEK_CUR: 파일의 현재 위치부터 계산
SEEK_END: 파일의 끝 위치부터 계산
소스
#include
#include
struct fullname {
char firstName[40];
char lastName[10];
} info;
int main(void){
FILE *fp;
if((fp=fopen("test", "rb")) == NULL) {
printf("Cannot open file.\n");
exit(1);
}
int client_num = 10;
/* find the proper structure */
fseek(fp, client_num*sizeof(struct fullname), SEEK_SET);
/* read the data into memory */
fread(&info, sizeof(struct fullname), 1, fp);
fclose(fp);
}
http://codesarang.com. mail to cpueblo cpueblo.com
|