#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;
}