How to specify dynamic array of characters (string) if not known initial size of the input string?

char str[100];
 scanf ("%s", &str);


How to specify str, if you do not know initially how long is the input string?
I tried using pointer, but it didn't work.

Tell me, please!
June 10th 19 at 15:58
3 answers
June 10th 19 at 16:00
Solution
Only allocate dynamically using malloc and read parts providesa memory after the limit is reached.
June 10th 19 at 16:02
I tried using pointer, but it didn't work.

That have tried, did not work?
June 10th 19 at 16:04
if the interest is academic, then as suggested by colleagues: malloc/calloc
if you need to work, take the glib (not to be confused with glibc)
if it is necessary to work, and glib is not satisfied (hard to imagine such a situation, but let's say), give more, for example, [512], but read only the first [500] (identity for example), scanf knows so. check how many was: if exactly 500 - user just entered a lot and most likely not fit all, swear at him (tell me that 256 was the max) and read again. if <500, then everything is OK, you can work. I hope it is clear explained: the main thing - not counting the data is larger than the allocated space (to avoid buffer overflow)

Find more questions by tags C