Initializacia

This commit is contained in:
Kozar 2024-11-12 16:12:28 +00:00
parent 6ec70db799
commit 3ecf143992

View File

@ -13,16 +13,13 @@ struct tree {
struct tree* read_tree() { struct tree* read_tree() {
char buffer[SIZE]; char buffer[SIZE];
memset(buffer, 0, SIZE); memset(buffer, 0, SIZE);
char* r = fgets(buffer, SIZE, stdin);
if (!fgets(buffer, SIZE, stdin) || buffer[0] == '\n') { if (!r || buffer[0] == '\n') {
return NULL; return NULL;
} }
buffer[strcspn(buffer, "\n")] = 0;
buffer[strcspn(buffer, "\n")] = 0; struct tree* node = calloc(1, sizeof(struct tree));
struct tree* node = (struct tree*)calloc(1, sizeof(struct tree));
strncpy(node->value, buffer, SIZE - 1); strncpy(node->value, buffer, SIZE - 1);
return node; return node;
} }