Prog#236: display nth record


#1
/*
display nth record
Program#236
*/
#include<stdio.h>
main(int argc,char *argv[])
{
int n,i,p,o;
int len;
union xyz{
struct bio{
char name [20], addr [20];
int age;
float salary;
}a;
char b[sizeof(struct bio)];
};
union xyz m;
if(argc!=2)
{
printf("file open error");
return 0;
}
p=open(argv[1], 0);
if(p==-1)
{
printf("file open error");
return 0;
}
scanf("%d", &n);
len=(n-1)*sizeof(struct bio);
lseek(p,len,o);
i=read(p,m.b,sizeof(struct bio));
printf("%s %d %f %s", m.a.name, m.a.age, m.a.salary, m.a.addr);
i=read(p,m.b,sizeof(struct bio));
close(p);
}