|
VMS Help CRTL, fgetpos, Example *Conan The Librarian |
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *fp;
int stat,
i;
int character;
char ch,
c_ptr[130],
d_ptr[130];
fpos_t posit;
/* Open a file for writing. */
if ((fp = fopen("file.dat", "w+")) == NULL) {
perror("open");
exit(1);
}
/* Get the beginning position in the file. */
if (fgetpos(fp, &posit) != 0)
perror("fgetpos");
/* Write some data to the file. */
if (fprintf(fp, "this is a test\n") == 0) {
perror("fprintf");
exit(1);
}
/* Set the file position back to the beginning. */
if (fsetpos(fp, &posit) != 0)
perror("fsetpos");
fgets(c_ptr, 130, fp);
puts(c_ptr); /* Should be "this is a test." */
/* Close the file. */
if (fclose(fp) != 0) {
perror("close");
exit(1);
}
}
|
|