-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibraryprogram.c
More file actions
119 lines (89 loc) · 2.11 KB
/
Copy pathlibraryprogram.c
File metadata and controls
119 lines (89 loc) · 2.11 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
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
//run with clang libraryprogram.c -lncurses (or another compiler)
char date[20];
char userName[20];
char bookName[20];
char telephoneNumber[20];
void write(); //writes book check out to record.txt file
void display(); //allows user to view books that were checked out on a given date
int main()
{
int selection;
char date[20];
do
{
clear();
//display user options
printf("Welcome to the library!!\n\n");
printf("Press 1 to add a book\n");
printf("Press 2 to display a date\n");
printf("press 3 to exit\n");
printf("enter a selection:\n");
scanf("%i", &selection);
switch(selection)
{
case 1:
write(); //writes book checkout to record.txt file
break;
case 2:
printf("\nEnter Date:");
scanf("%s", date);
display(date); //allows user to view books that were checked out on a given date
break;
case 3:
exit(0);
default:
printf("\nInvalid selection");
}
getch();
} while (selection != 0);
} //closes main
void write()
{
FILE *fp;
char date[20];
char userName[20];
char bookName[20];
char telephoneNumber[20];
//user inputs information for check out
printf("Enter today's date: \t\t\n");
scanf("%s", date);
printf("Enter your name: \t\t\n");
scanf("%s", userName);
printf("Enter your telephone number: \t\t\n");
scanf("%s", telephoneNumber);
printf("Enter the book's name: \t\t\n");
scanf("%s", bookName);
fp = fopen("Record.txt", "a");
//appends entry to Record.txt
fprintf(fp, "\n%s %s %s %s\n", date,
userName,
telephoneNumber,
bookName
);
printf("Transaction was saved\n");
fclose(fp);
}
void display(char dateKey[])
{
FILE *fp;
fp = fopen("Record.txt","r");
while(fscanf(fp, "%s %s %s %s\n", date,
userName,
telephoneNumber,
bookName
) != EOF)
{
// prints record if dates match
if(strcmp(date, dateKey) == 0)
{
printf("\n\n Name = %s\n", userName);
printf("Telephone = %s\n", telephoneNumber);
printf("Book Name = %s\n", bookName);
}
}
fclose(fp);
}