-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.c
More file actions
57 lines (53 loc) · 1.49 KB
/
entry.c
File metadata and controls
57 lines (53 loc) · 1.49 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
#include <stdio.h>
#include <string.h>
#include "entry.h"
void add_entry(Entry *entries, int *count) {
if (*count >= MAX_ENTRIES) {
printf("Max entries reached.\n");
return;
}
printf("Enter site: ");
scanf("%s", entries[*count].site);
printf("Enter username: ");
scanf("%s", entries[*count].user);
printf("Enter password: ");
scanf("%s", entries[*count].password);
(*count)++;
}
void list_entries(Entry *entries, int count) {
for (int i = 0; i < count; i++) {
printf("%d. %s | %s | %s\n", i + 1, entries[i].site, entries[i].user, entries[i].password);
}
}
void edit_entry(Entry *entries, int count) {
int index;
list_entries(entries, count);
printf("Select entry to edit (1-%d): ", count);
scanf("%d", &index);
index--;
if (index < 0 || index >= count) {
printf("Invalid entry.\n");
return;
}
printf("Enter new site: ");
scanf("%s", entries[index].site);
printf("Enter new username: ");
scanf("%s", entries[index].user);
printf("Enter new password: ");
scanf("%s", entries[index].password);
}
void delete_entry(Entry *entries, int *count) {
int index;
list_entries(entries, *count);
printf("Select entry to delete (1-%d): ", *count);
scanf("%d", &index);
index--;
if (index < 0 || index >= *count) {
printf("Invalid entry.\n");
return;
}
for (int i = index; i < *count - 1; i++) {
entries[i] = entries[i + 1];
}
(*count)--;
}