-
Notifications
You must be signed in to change notification settings - Fork 0
/
addbook_functions.cpp
97 lines (97 loc) · 2.03 KB
/
addbook_functions.cpp
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
void addbooks()
{
int choice;
char ch,data[15];
FILE *fp;
color();
setcolor(BLUE);
settextstyle(7,0,5);
outtextxy(180,30,"ADD BOOK PAGE");
gotoxy(30,8);
printf("ENTER BOOK ID : ");
fflush(stdin);
scanf("%s",data);
fp=fopen("book.txt","ab");
if(fp==NULL)
{
printf("Can't Open File");
exit(1);
}
fclose(fp);
fp=fopen("book.txt","rb");
if(fp==NULL)
{
printf("Can't Open File");
exit(1);
}
fread(&books,sizeof(books),1,fp);
while(!feof(fp))
{
if((strcmp(data,books.id))==0)
{
gotoxy(27,12);
printf("THIS BOOK ID HAVE BEEN ALREADY ADDED");
gotoxy(35,14);
printf("SELECT CHOICE ");
gotoxy(35,16);
printf("1) CREATE ID");
gotoxy(35,18);
printf("2) BACK MENU");
gotoxy(40,20);
scanf("%d",&choice);
if(choice==1)
addbooks();
else
adminmenu();
}
fread(&books,sizeof(books),1,fp);
}
fclose(fp);
strcpy(books.id,data);
gotoxy(30,10);
printf("ENTER TITLE : ");
fflush(stdin);
scanf("%[^\n]s",&books.title);
fflush(stdin);
gotoxy(30,12);
printf("ENTER AUTHOR NAME : ");
fflush(stdin);
scanf("%[^\n]s",&books.author);
gotoxy(30,14);
printf("ENTER QUANTITY : ");
fflush(stdin);
scanf("%d",&books.q);
gotoxy(30,16);
printf("ENTER SHELF NO : ");
fflush(stdin);
scanf("%d",&books.sn);
gotoxy(30,18);
printf("PRESS Y TO ADD BOOK : ");
fflush(stdin);
scanf("%s",&ch);
if(ch=='y'|| ch=='Y')
addbook("add");
else
{ gotoxy(45,21);
printf("NOT ADDED");
}
adminmenu();
}
void addbook(char status[10])
{
FILE *fp;
fp=fopen("book.txt","ab");
if(fp==NULL)
{
printf("Unable to open file!!!");
getch();
exit(0);
}
fwrite(&books,sizeof(books), 1, fp);
fclose(fp);
if((strcmp(status,"add"))==0)
{ gotoxy(45,21);
printf("ADDED");
getch();
}
}