#include
main()
{
FILE *fp;
fp = fopen("./ftest.txt", "r+");
printf("start..pos->[%ld]\n", ftell(fp));
fseek(fp, 20, SEEK_SET);
printf("now..pos->[%ld]\n", ftell(fp));
fprintf(fp,"this..");
printf("end..pos->[%ld]\n", ftell(fp));
}
위의 소스를 실행하면...
start..pos->[0]
now..pos->[20]
end..pos->[26]
위와 같은 결과가 나옵니다.
처음에 열기전의 파일 크기는 9였고
위의 프로그램을 실행한후 파일크기는 26이었습니다.
그리고 그 결과 파일을 vi로 열어보면..
123456789^@^@^@^@^@^@^@^@^@^@^@this..