Code Competitions

Coding competition
Showing posts with label fsetpos use in list. Show all posts
Showing posts with label fsetpos use in list. Show all posts

Tuesday, 14 May 2013

program to set pointer position in file

#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp;
    fpos_t loc;
    int i,a[40],n;
    clrscr();
    fp=fopen("series.txt","w");
    printf("enter the number of elements ");
    scanf("%d",&n);
    printf("\nenter the elements ");
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        fprintf(fp,"%d ",a[i]);
    }
    fclose(fp);
    printf("the series is  ");
    fp=fopen("series.txt","r");
    for(i=0;i<n;i++)
    {
        fscanf(fp,"%d\t",&a[i]);
        printf("%4d",a[i]);
    }
    //fgetpos(fp,&loc);
    printf("the series is  ");
    rewind(fp);
    loc=loc+2;
    fsetpos(fp,&loc);
    fscanf(fp,"%d",&a[i]);
    printf("%4d",a[i]);
    getch();
}