I want to read a string (str) from the user and a number (num) via scanf() but I don't know how to initialize str correctly.
int main(void)
{
char *str = NULL;
int num;
scanf("%s %d", str, &num);
printf("str: %s\nnum: %d\n", str, num);
}
If I do it like this I get a segmentation fault.
My problem is that I don't know the length of str so I can't say something like this:
char str[20];
and I'm also not allowed to hardcode some high amount of index e.g.:
char str[999];
My question now: How can I initialize str in this case?