CodeSarang.Com
Home | 전체 메뉴 | 질문/답변 Join | Login | 검색   

 

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 <stdio.h> #include <stdlib.h> 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 cpueblocpueblo.com