/* program to understand the fseek() */
Employee
{
name[20];
age;
sallary;
}emp;
main()
{
n;
*fptr;
fptr=fopen("myfile","rb");
(fptr==NULL)
{
printf("Error when open file" );
}
printf("Enter any record number to read " );
scanf("%d", &n);
fseek(fptr,(n-1)*sizeof(emp),0); /* skip n-1 records */
fread(&emp,sizeof(emp),1,fptr); /* read the nth record */
printf("%s\n", emp.name);
printf("%d\n", emp.age);
printf("%f \n", emp.sallary);
fclose(fptr);
0;
}
|