#include #include #include #include char look; #define CHUNK_SIZE 16 #define read_char() do { look = getc(stdin); } while (0) int get_name(char **name) { int i = 0; int chunk_size = CHUNK_SIZE; char *buffer = calloc(chunk_size, sizeof(char)); while (!isspace(look)) { buffer[i++] = look; read_char(); if (i == chunk_size) { chunk_size += CHUNK_SIZE; buffer = realloc(buffer, chunk_size * sizeof(char)); } } *name = calloc(i, sizeof(char)); memmove(*name, buffer, i * sizeof(char)); free(buffer); return i; } void init() { read_char(); } int main() { init(); char* name; get_name(&name); printf("Name: %s\n", name); free(name); return 0; }