-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab11q1.c
More file actions
71 lines (56 loc) · 1.21 KB
/
Copy pathlab11q1.c
File metadata and controls
71 lines (56 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char name[20];
int age;
double GPA;
}stu_t;
int main()
{
FILE*inp;
inp = fopen("stu.bin", "rb");
stu_t arr;
int size = 15;
int X;
int cho;
//size = fread(&arr, sizeof(stu_t), 15, inp);
//for (int i = 0; i < size; i++)
//{
//printf("%s %d %0.2f\n", arr[i].name, arr[i].age, arr[i].GPA);
//}
printf("1.)Go to record X from top\n");
printf("2.)Move X record ahead\n");
printf("3.)Go X records back from\n");
printf("4.)Exit\n");
printf("Enter your choice:");
scanf("%d", &cho);
switch (cho)
{
case 1:
printf("Enter X:");
scanf("%d", &X);
fseek(inp, sizeof(stu_t)*(X-1), SEEK_SET);
fread(&arr, sizeof(stu_t), 1, inp);
printf("%s %d %0.2f", arr.name, arr.age, arr.GPA);
break;
case 2:
printf("Enter X:");
scanf("%d", &X);
fseek(inp, sizeof(stu_t)*(X - 1), SEEK_CUR);
fread(&arr, sizeof(stu_t), 1, inp);
printf("%s %d %0.2f", arr.name, arr.age, arr.GPA);
break;
case 3:
printf("Enter X:");
scanf("%d", &X);
fseek(inp, sizeof(stu_t)*(-X), SEEK_END);
fread(&arr, sizeof(stu_t), 1, inp);
printf("%s %d %0.2f", arr.name, arr.age, arr.GPA);
break;
case 4:
return 0;
break;
}
system("PAUSE");
return 0;
}