fseek in C




File Operations in Tamil


fseek in C

  • It is used to move the reading control to different positions using fseek function.
 c-fseek

C Syntax

 fseek( file pointer, displacement, pointer position);

file pointer : It is the pointer which points to the file.
displacement : It is positive or negative. This is the number of bytes which are skipped backward (if negative) or forward( if positive) from the current position. This is attached with L because this is a long integer.
pointer position : This sets the pointer position in the file.

fseek( p,10L,0)

  • 0 means pointer position is on beginning of the file, from this statement pointer position is skipped 10 bytes from the beginning of the file.

fseek( p,5L,1)

  • 1 means current position of the pointer position. From this statement pointer position is skipped 5 bytes forward from the current position.

fseek(p,-5L,1)

  • From this statement pointer position is skipped 5 bytes backward from the current position.

Sample Code

#include<stdio.h>
#include<conio.h>
  void main() {
    FILE * fp;
    char ch;
    int n;
    fp = fopen("one.txt", "r");
    if (fp == NULL) {
      printf("file cannot be opened");

    } else {
      printf("Enter value of n to read last ā€˜nā€™ characters");
      scanf("%d", & n);
      fseek(fp, -n, 2);
      while ((ch = fgetc(fp)) != EOF) {
        printf("%c\t", ch);
      }
    }
    fclose(fp);
  }
 c-fseek

Output

 c-fseek

Learn C - C tutorial - C fseek - C examples - C programs



View More Quick Examples


Related Searches to fseek in C

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

Ɨ