-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMini Project
More file actions
106 lines (98 loc) · 2.65 KB
/
Mini Project
File metadata and controls
106 lines (98 loc) · 2.65 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void flush()
{
int a;
while ((a=getchar()) !='\n' && a != EOF);
}
int main()
{
FILE *aco,*dco;
char more,option;
struct code{
char code[80];
char product_name[40];
int manufacture_date;
int expiry_date;
};
struct code p;
char product_name[40];
long int codelist;
aco=fopen("code.txt","rb+");
if (aco== NULL);{
aco=fopen("code.txt","wb+");
if(aco== NULL) {
printf("no file is there !");
exit(1);
}
}
printf("////////////welcome to store////////////\n");
printf("////////here you will get all the information about product///////\n");
printf("/////////below are the options choose one!////////////\n");
codelist= sizeof(p);
while(1){
printf("a]add information\n");
printf("b]display code\n");
printf("c]delete information\n");
printf("d]close\n");
printf("choose one\n");
fflush(stdin);
scanf("\n%c", &option);
switch(option)
{
case 'a':
fseek(aco,0,SEEK_END);
more='o';
while(more=='o'){
flush();
printf("\nnew code:");
fgets(p.code,80,stdin);
printf("\nProduct name: ");
fgets(p.product_name,40,stdin);
printf("\nmanufacture date:");
scanf("%d",&p.manufacture_date);
printf("\nexpiry date: ");
scanf("%d",&p.expiry_date);
fwrite(&p,codelist,1,aco);
printf("\nadd one more or exit(o/e)");
fflush(stdin);
scanf("\n%c", &more);
}
break;
case 'b':
rewind(aco);
while(fread(&p,codelist,1,aco)==1){
printf("\n%s %s %d %d\n",p.code,p.product_name,p.manufacture_date,p.expiry_date);
}
break;
case 'c':
more='o';
while (more=='o'){
flush();
printf("delete code:");
fgets(product_name,80,stdin);
dco=fopen("code1.txt","wb");
rewind(aco);
while (fread(&p,codelist,1,aco)==1){
if(strcmp(p.code,product_name)!=0){
fwrite(&p,codelist,1,dco);
}
}
fclose(aco);
fclose(dco);
remove("code,txt");
rename("code1.txt","code,txt");
aco=fopen("code.txt","rb+");
printf("delete another record(o/e)");
fflush(stdin);
scanf("\n%c",&more);
}
break;
case 'd':
fclose(aco);
exit(0);
}
}
return 0;
}