/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that reads the third charter
in a file. */ 
#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *stream;
    char ch;
    int cur_indicator;
    long int offset = 2*sizeof(char); 
    /* open file for reading and writing */
    if((stream = fopen("ftell.c","r")) == NULL){ 
      printf("cannot open file\n");
      exit(1);
    }
    fseek(stream,offset,0);     //search the third character
    cur_indicator = ftell(stream);      // read current indicator
    fread(&ch,sizeof(char),1,stream);   //read a character
    printf("The third character in file is '%c'\n",ch);
    fseek(stream,cur_indicator-1,0);   // set the file indicator to
                                       // the number before the current
    fread(&ch,sizeof(char),1,stream);   //read a character
    printf("The second character in file is '%c'\n",ch);
    rewind(stream);                     //set file indicator to first
    fread(&ch,sizeof(char),1,stream);
    printf("The first character in file is '%c'\n",ch); 
    fclose(stream);
}
