1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

feat: add string type

This commit is contained in:
2023-06-25 15:01:25 +02:00
parent ce088f8ff5
commit 8f3ee199e5
13 changed files with 172 additions and 194 deletions

View File

@ -1,22 +1,22 @@
#include "terminal.h"
char* terminal_input() {
string terminal_input() {
char character;
size_t length = 1;
char* string = malloc(length * sizeof(char));
if (string == NULL) {
string string_value = malloc(length * sizeof(char));
if (string_value == NULL) {
exit(EXIT_FAILURE);
}
*string = '\0';
*string_value = '\0';
while ((character = getchar()) != '\n' && character != EOF) {
length++;
string = realloc(string, length * sizeof(char));
if (string == NULL) {
string_value = realloc(string_value, length * sizeof(char));
if (string_value == NULL) {
exit(EXIT_FAILURE);
}
character_append(string, character);
character_append(string_value, character);
}
return string;
return string_value;
}
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) {