Dynamically prompt for string without knowing string size
问题 In C, what is the best way of prompting and storing a string without wasted space if we cannot prompt for the string length. For example, normally I would do something like the following... char fname[30]; char lname[30]; printf("Type first name:\n"); scanf("%s", fname); printf("Type last name:\n"); scanf("%s", lname); printf("Your name is: %s %s\n", fname, lname); However, I'm annoyed with the fact that I have to use more space than needed so I do not want to use char fname[30] , but instead