예제 | #include <stdio.h>
int main( void)
{
FILE *fp;
char str[1024];
int ndx;
fp = fopen( "./test.txt", "r");
printf( "%sn", fgets( str, 1024, fp));
fseek( fp, 10, SEEK_SET); // 파일의 시작에서 10번을 건너 띈다.
printf( "%sn", fgets( str, 1024, fp));
fseek( fp, 5, SEEK_SET); // 파일의 시작에서 5번을 건너 띈다.
fseek( fp, 5, SEEK_CUR); // 현재 위치에서 다시 5번을 건너 띈다.
printf( "%sn", fgets( str, 1024, fp));
fseek( fp, -5, SEEK_END); // 파일의 시작에서 5번을 건너 띈다.
printf( "%sn", fgets( str, 1024, fp));
fclose( fp);
return 0;
}
test.txt 파일에 16진수 문자, 0부터 f 까지 입력되어 있을 때 실행 결과입니다. 0123456789abcdef
]$ ./a.out
0123456789abcdef
abcdef
abcdef
bcdef
]$
|