include stdio include math include stdlib include string define 15 str

  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
120
121
122
123
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define N 15
struct libary {
int AllCount;
struct books {
char author[N];
char name[N];
char code[N];
} AllBooks[N*N*N];
} lib;
int i;
void addLine() {
char a[N],b[N],c[N];
printf("Write author's name: ");
scanf("%s", a);
printf("Write book's name: ");
scanf("%s", b);
printf("Write book's code: ");
scanf("%s", c);
strcpy(lib.AllBooks[ lib.AllCount ].author, a);
strcpy(lib.AllBooks[ lib.AllCount ].name, b);
strcpy(lib.AllBooks[ lib.AllCount ].code, c);
lib.AllCount++;
}
void showLines() {
printf("Num %15s %14s %15s", "Author", "Name", "Code\n");
for(i = 0; i < lib.AllCount; i++) {
printf("%d %15s %15s %15s \n", i+1,
lib.AllBooks[i].author, lib.AllBooks[i].name, lib.AllBooks[i].code );
}
}
void deleteLine() {
int number;
showLines();
printf("Type line number: ");
scanf("%d", &number);
if(number > 0 && number <= lib.AllCount ) {
number--;
for(i = number; i < lib.AllCount - 1; i++) {
strcpy(lib.AllBooks[ i ].author, lib.AllBooks[ i + 1 ].author);
strcpy(lib.AllBooks[ i ].name, lib.AllBooks[ i + 1 ].name);
strcpy(lib.AllBooks[ i ].code, lib.AllBooks[ i + 1 ].code);
}
lib.AllCount--;
}
}
void editLine() {
char a[N];
int number, field;
showLines();
printf("Type line number: ");
scanf("%d", &number);
printf("1. Author\n");
printf("2. Name\n");
printf("3. Code\n");
printf("Type field number: ");
scanf("%d", &field);
if(number > 0 && number <= lib.AllCount && field > 0 && field < 4 ) {
number--;
switch(field) {
case 1:
printf("Write new author's name: ");
scanf("%s", a);
strcpy(lib.AllBooks[ number ].author, a);
break;
case 2:
printf("Write new book's name: ");
scanf("%s", a);
strcpy(lib.AllBooks[ number ].name, a);
break;
case 3:
printf("Write new book's code: ");
scanf("%s", a);
strcpy(lib.AllBooks[ number ].code, a);
break;
}
}
}
void print() {
printf("---------------------########---------------------\n");
printf("1. Add line\n");
printf("2. Delete line\n");
printf("3. Show lines\n");
printf("4. Edit line\n");
printf("5. Exit\n");
printf("Choose menu item: ");
}
int main() {
int type = 0;
print();
lib.AllCount = 0;
while(scanf("%d", &type)) {
switch(type) {
case 1:
addLine();
break;
case 2:
deleteLine();
break;
case 3:
showLines();
break;
case 4:
editLine();
break;
case 5:
return 0;
}
print();
}
return 0;
}