/
Roman-git
/
Eltex_tasks
Обзор
Документация
Войти
/
Roman-git
/
Eltex_tasks
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
task_4/menu.c
137 строк
3 KB
Roman_git
correction task_4
23 дек 2024, 09:32
23 дек 2024, 09:32
b857496
Код
Авторство
О чём код?
#include "menu.h" #include <stdio.h> #include <stdlib.h> #include <string.h> void add_title(struct phonebook PB[]) { strcpy(PB[0].name, "Name"); strcpy(PB[0].second_name, "Surname"); strcpy(PB[0].tel ,"Phonle"); } void print_menu() { printf("\n1. Add the subscriber \n2. Remove the subscriber "); printf("\n3. Search of the subscriber by name \n4. Display all records \n5. Exit\n\n"); } ////////////////////////////////////////////////////////////////////////////////////////// int input_menu() { int temp; printf("Enter point menu: "); scanf("%d", &temp); return temp; } ////////////////////////////////////////////////////////////////////////////////////////// void Add_sub(struct phonebook PB[]) { if (n > 100) { printf("\nThe directory is full\n"); } else { printf("\nAdd the subscriber: \n"); n++; printf("\nName: "); scanf("%s", PB[n-1].name); printf("Second_name: "); scanf("%s", PB[n-1].second_name); printf("Tel: "); scanf("%s", PB[n-1].tel); } } ////////////////////////////////////////////////////////////////////////////////////////// void Remove_sub(struct phonebook PB[], struct phonebook temp_PB) { int count_name_remove = 0; char remove_name[10]; printf("\nName remove: "); scanf("%s", remove_name); for (int i=1; i < n; i++) { if (strcmp (PB[i].name, remove_name)==0) { strcpy(temp_PB.name, PB[i].name); strcpy(temp_PB.second_name,PB[i].second_name); strcpy(temp_PB.tel , PB[i].tel); strcpy(PB[i].name, PB[i+1].name); strcpy(PB[i].second_name,PB[i+1].second_name); strcpy(PB[i].tel , PB[i+1].tel); strcpy(PB[i+1].name, temp_PB.name); strcpy(PB[i+1].second_name,temp_PB.second_name); strcpy(PB[i+1].tel , temp_PB.tel); count_name_remove++; } } if (count_name_remove == 0) { printf("\nSubscriber is absent\n"); } else { memset(PB[n].name, 0, 10); memset(PB[n].second_name, 0, 10); memset(PB[n].tel, 0, 10); n--; } } ////////////////////////////////////////////////////////////////////////////////////////// void Display_sub(struct phonebook PB[]) { printf("\nAll subscribers:\n\n"); for (int i=0; i < n; i++) { printf("%s %s %s\r\n", PB[i].name, PB[i].second_name, PB[i].tel); } } ////////////////////////////////////////////////////////////////////////////////////////// void Search_sub(struct phonebook PB[]) { printf("\nSearch of the subscriber by name\n"); int count_name_search = 0; char search_name[10]; int count = 0; scanf("%s", search_name); for (int i=0; i <= n; i++) { if (strcmp (PB[i].name, search_name)==0) {count++; printf("%s %s %s\n", PB[i].name, PB[i].second_name, PB[i].tel); } else count_name_search = count_name_search + count; } if (count_name_search == 0) printf("\nSubscriber is absent\n"); } //////////////////////////////////////////////////////////////////////////////////////////