int main(int argc, char** argv) { int strLen = 5; char ch; char* str = (char*)malloc(sizeof(char*) * strLen); int count = 0; printf("Please input a string: "); do { ch = getchar(); count++; if (count >= strLen) { str = (char*)realloc(str, sizeof(char*) * (++strLen)); } str[count-1] = ch; } while (ch != '\n'); str[count] = '\0'; puts(str); return 0; }