|
发表于 2018-9-14 21:56:22
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h>
- int main(void)
- {
- FILE *file = fopen("test.txt", "rb");
- char buf[100];
- fread(buf, 1, 10, file);
- for(int i = 0; i < 10; ++i)
- {
- printf("buf[%d] = '%c'\n", i, buf[i]);
- }
- int ch;
- fpos_t pos;
- pos = 0;
- fsetpos(file, &pos);
- ch = fgetc(file);
- printf("0 -> '%c'\n", ch);
- pos = 3;
- fsetpos(file, &pos);
- ch = fgetc(file);
- printf("3 -> '%c'\n", ch);
- pos = 0;
- fsetpos(file, &pos);
- for(int i = 0; i < 3; ++i)
- {
- putchar(fgetc(file));
- }
- printf("\n");
- fgetpos(file, &pos);
- printf("pos = %lld\n", pos);
- fclose(file);
- return 0;
- }
复制代码 |
|