Pages

Saturday, 18 July 2020

fseek demo program

Q : Write a file statement to place a file pointer (fp) at the beginning of the record number (say R), where record size is B bytes.


Answer : 

#include<stdio.h>

#include<conio.h>

/*============================

     Girfa Student Help

     fseek demo

==============================*/

struct emp

{

     int empid;

     char empname[50];

};

void main()

{

     FILE *ft;

     int record;

     clrscr();

     printf("Enter record number>> ");

     scanf("%d",&record);

     ft=fopen("data.txt","r");

     if(ft==NULL)

           puts("File Opening error");

     else

           fseek(ft,sizeof(struct emp)*record,0);

}

No comments:

Post a Comment