Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

ILLUSTRATION OF fseek & ftell FUNCTIONS

Posted By: Lola Hughes     Category: C Programming     Views: 6373

rite a program that uses the functions ftell and fseek.

Code for ILLUSTRATION OF fseek & ftell FUNCTIONS in C Programming

#include <stdio.h>                                             
   main()                                                           
   {                                                                
       FILE  *fp;                                                   
       long  n;                                                     
       char c;                                                      
       fp = fopen("RANDOM", "w");                                   
       while((c = getchar()) != EOF)                                
           putc(c,fp);                                              
                                                                    
       printf("No. of characters entered = %ld\n", ftell(fp));      
       fclose(fp);                                                  
       fp = fopen("RANDOM","r");                                    
       n = 0L;                                                      
                                                                    
       while(feof(fp) == 0)                                         
       {                                                            
           fseek(fp, n, 0);  /*  Position to (n+1)th character */
printf("Position of %c is %ld\n", getc(fp),ftell(fp)); n = n+5L; } putchar('\n'); fseek(fp,-1L,2); /* Position to the last character */
do { putchar(getc(fp)); } while(!fseek(fp,-2L,1)); fclose(fp); } Output ABCDEFGHIJKLMNOPQRSTUVWXYZ^Z No. of characters entered = 26 Position of A is 0 Position of F is 5 Position of K is 10 Position of P is 15 Position of U is 20 Position of Z is 25 Position of is 30 ZYXWVUTSRQPONMLKJIHGFEDCBA
  
Share: 


Didn't find what you were looking for? Find more on ILLUSTRATION OF fseek & ftell FUNCTIONS Or get search suggestion and latest updates.

Lola Hughes
Lola Hughes author of ILLUSTRATION OF fseek & ftell FUNCTIONS is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!