/* Copyright (c) 2001-2009 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;
    long int offset;

    offset = 2*sizeof(char);    
    /* open file for reading and writing */
    if((stream = fopen("fseek.c","r")) == NULL){ 
      printf("cannot open file\n");
      exit(1);
    }
    fseek(stream,offset,0);     //search the third character
    fread(&ch,sizeof(char),1,stream);   //read a character
    printf("The third 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);
}
