home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <fcntl.h>
-
- main()
- {
- FILE *f;
- int fd;
- char buf[10];
- f = fopen("t14.dat", "w");
- fwrite("abcdefghijklmnopqrstuvxyz\n", 26, 1, f);
- fclose(f);
-
- fd = open("t14.dat", O_WRONLY|O_BINARY);
- if (fd < 0)
- return -1;
- ftruncate(fd, 20);
- close(fd);
-
- f = fopen("t14.dat", "r");
- fread(buf, 5, 1, f);
- buf[5] = 0;
- printf("first pass: %s\n", buf);
- rewind(f);
- fread(buf, 5, 1, f);
- buf[5] = 0;
- printf("second pass: %s\n", buf);
- fclose(f);
-
- return 0;
- }
-