I wanna know how would you scan a string on unknown length? Suppose I ask for someone's full name and that includes spaces too and just want to scan what the input is and print it. I read a few answers about this but all included a long function using malloc/realloc. Is there a way I could ask for the input and just print it in the main function itself?
#include <stdio.h>
int main(void)
{
char name[100][100];
int i,n;
printf("\nEnter The Limit : ");
scanf("%d", &n);
for(i=0; i<n; i++)
scanf("%s\n"),name[i]);
for(i=0; i<n; i++)
printf("\n%s",name[i]);
}
This is as far as I can think of, I can only put a limit to the number of characters you enter, is there any other better way to do it? Could I use strlen here if it's possible?
I read this question How can I read a input string on unknown length in c? The answers here mention using a different function, I want to know if there is a simpler way to do it ? C programmers often make big programs where they ask for the name of the person including fullname? Do all of you use the large function as mentioned in the answered question or is there a simpler way?
Thanks for answering!