When I was practicing string in Hackerrank, they showed me a new approach to get string input in C that I had never seen before. This is code:
char *s;
s = malloc(1024 * sizeof(char));
scanf("%[^\n]", s);
s = realloc(s, strlen(s) + 1);
Can you explain that how these thing work? In a lot of program I always get string input by this way:
char *s[MAX_LEN];
fflush(stdin);
gets(s);
Thank you!