/
Korsun_M
/
KP9
Обзор
Документация
Войти
/
Korsun_M
/
KP9
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Table.c
76 строк
2 KB
MiAmour
first_commit
29 апр 2026, 12:55
29 апр 2026, 12:55
f29d06f
Код
Авторство
О чём код?
#include "Table.h" #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <ctype.h> #include <unistd.h> typedef struct Table_Item { int key; int data; } Table_Item; Table_Item * Table_Item_read() { int c; // bool key_done = false; Table_Item * item = malloc(sizeof(Table_Item)); item->key = 0; item->data = 0; if (isatty(STDIN_FILENO)) { printf("Insert a key: "); while ((c = getchar()) != '\n' && c != EOF) { if (isdigit(c)) item->key = item->key * 10 + c - '0'; else { printf("Error: Only digits are required\n"); } } printf("Insert a value: "); while ((c = getchar()) != '\n' && c != EOF) { if (isdigit(c)) item->data = item->data * 10 + c - '0'; else { printf("Error: Only digits are required\n"); } } } // while ((c = getchar()) != '\n' && c != EOF) { // if (isdigit(c)) { // if (key_done) item->data = item->data * 10 + c -'0'; // else item->key = item->key * 10 + c - '0'; // } // if (isspace(c)) { // key_done = true; // } return item; } void Table_Item_print(Table_Item * item, FILE * output_file) { if (output_file == stdout) printf("Key: %d Data: %d\n", item->key, item->data); else { fseek(output_file, 0, SEEK_END); fprintf(output_file, "%d %d\n", item->key, item->data); } } // void Table_generate(Table_Item * Table[]) { // for (int i = 0; i < 10; ++i) { // Table[i] = (Table_Item *)malloc(sizeof(Table_Item)); // Table[i]->key = i; // Table[i]->data = malloc(sizeof(char)); // *(char *)Table[i]->data = i + 'a'; // } // } // void Binary_search(Table_Item * Table[]) { // printf("%zu\n", sizeof(*Table)); // } // void Table_print(Table_Item * Table[]) { // FILE * file = fopen("tables/ordered.txt", "wb"); // fprintf(file, " key (int)\t|\tvalue (char)\n____________________________\n"); // for (int i = 0; i < 10; ++i) { // fprintf(file, "\t%d\t\t|\t\t%c\n", Table[i]->key, *(char *)Table[i]->data); // } // fclose(file); // }